Jump to content

How to make a loop abouth always changing WinWaitActivate title


 Share

Recommended Posts

Hello guys i hope your days going well.

I'm newbie coding in autoit so if it's simple sorry for take a time.

My problem is window name should change like "abc.com/1  ,  abc.com/2   ,  abc.com/3" that

I tryed to make a loop for it but i fail too many times like you guys can see the code. Please some one can help me ? Maybe it's so simple for you but it's so big thing for me  :(

It's going like that until 311 and i don't wanna repait it like that again and again i shoul make "for-next" loop :(

#region --- Au3Recorder generated code Start (v3.3.9.5 KeyboardLayout=0000041F)  ---

#region --- Internal functions Au3Recorder Start ---
Func _Au3RecordSetup()
Opt('WinWaitDelay',100)
Opt('WinDetectHiddenText',1)
Opt('MouseCoordMode',0)

Local $aResult = DllCall('User32.dll', 'int', 'GetKeyboardLayoutNameW', 'wstr', '')
If $aResult[1] <> '0000041F' Then
  MsgBox(64, 'Warning', 'Recording has been done under a different Keyboard layout' & @CRLF & '(0000041F->' & $aResult[1] & ')')
EndIf

EndFunc

Func _WinWaitActivate($title,$text,$timeout=0)
    WinWait($title,$text,$timeout)
    If Not WinActive($title,$text) Then WinActivate($title,$text)
    WinWaitActive($title,$text,$timeout)
EndFunc

_AU3RecordSetup()
#endregion --- Internal functions Au3Recorder End ---

   $sayfa= $sayfa+1
_WinWaitActivate("https://www.uygunparca.com/index.php?route=module/browse/ajax_model&p=59_68&manufacturer_id=13&category_id=68&page=151 - Google Chrome","Chrome Legacy Window")

MouseMove(12,258)
MouseDown("left")
MouseMove(257,964)
MouseUp("left")
Send("{CTRLDOWN}c{CTRLUP}")
_WinWaitActivate("Program Manager","FolderView")
MouseClick("left",700,1063,1)
_WinWaitActivate("Microsoft Excel - Yeni Microsoft Office Excel Çalışma Sayfası","Yeni Microsoft Offic")
Send("{CTRLDOWN}v{CTRLUP}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}")
_WinWaitActivate("Program Manager","FolderView")
MouseClick("left",721,1056,1)

_WinWaitActivate("https://www.uygunparca.com/index.php?route=module/browse/ajax_model&p=59_68&manufacturer_id=13&category_id=68&page=151 - Google Chrome","Chrome Legacy Window")
MouseClick("left",1048,55,1)
Sleep (2000)
MouseMove(1047,63)
MouseDown("left")
MouseMove(1049,65)
MouseUp("left")

Send("{BACKSPACE}{BACKSPACE}{BACKSPACE}152{ENTER}");~ here for change to website address it's deleting last 151 number writing 152 and pressing enter after that doing same things again and again.

_WinWaitActivate("https://www.uygunparca.com/index.php?route=module/browse/ajax_model&p=59_68&manufacturer_id=13&category_id=68&page=152 - Google Chrome","Chrome Legacy Window")
Send("{CTRLDOWN}")
MouseMove(11,252)
MouseDown("left")
MouseMove(112,971)
MouseUp("left")
Send("cccc{CTRLUP}")
_WinWaitActivate("Program Manager","")
MouseClick("left",650,1073,1)
Sleep (2000)
_WinWaitActivate("Microsoft Excel - Yeni Microsoft Office Excel Çalışma Sayfası","")
Send("{CTRLDOWN}v{CTRLUP}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}")
_WinWaitActivate("Program Manager","")
MouseClick("left",651,1076,1)
Sleep (2000)
_WinWaitActivate("https://www.uygunparca.com/index.php?route=module/browse/ajax_model&p=59_68&manufacturer_id=13&category_id=68&page=152 - Google Chrome","Chrome Legacy Window")
MouseClick("left",1026,64,1)
Sleep (2000)
MouseClick("left",1026,64,1)
Sleep (2000)
Send("{BACKSPACE}{BACKSPACE}{BACKSPACE}153{ENTER}")
_WinWaitActivate("https://www.uygunparca.com/index.php?route=module/browse/ajax_model&p=59_68&manufacturer_id=13&category_id=68&page=153 - Google Chrome","Chrome Legacy Window")
Send("{CTRLDOWN}")
MouseMove(11,252)
MouseDown("left")
MouseMove(112,971)
MouseUp("left")
Send("cccc{CTRLUP}")
_WinWaitActivate("Program Manager","")
MouseClick("left",650,1073,1)
Sleep (1000)
_WinWaitActivate("Microsoft Excel - Yeni Microsoft Office Excel Çalışma Sayfası","")
Send("{CTRLDOWN}v{CTRLUP}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}")
_WinWaitActivate("Program Manager","")
MouseClick("left",651,1076,1)
Sleep (1000)
_WinWaitActivate("https://www.uygunparca.com/index.php?route=module/browse/ajax_model&p=59_68&manufacturer_id=13&category_id=68&page=153 - Google Chrome","Chrome Legacy Window")
MouseClick("left",1026,64,1)
Sleep (1000)
MouseClick("left",1026,64,1)
Sleep (1000)
Send("{BACKSPACE}{BACKSPACE}{BACKSPACE}154{ENTER}")


#endregion --- Au3Recorder generated code End ---

 

Link to comment
Share on other sites

You should look at using IE UDF and Excel UDF much better then using Mouse... and Send functions.  But to loop you just need to use something like:

For $i = 150 To 155
    MsgBox(4096, "", "http://abc.com/" & $i)
Next

Here is how to copy all the links into Excel using IE and Excel UDF.

#include <Array.au3>
#include <Excel.au3>
#include <IE.au3>
Local $aLinks[0][2]
$oIE = _IECreate("https://www.uygunparca.com/index.php?route=module/browse/ajax_model&p=59_68&manufacturer_id=13&category_id=68&page=150", 1)
_IELoadWait($oIE)
Local $iPageStart = 151, $iPageEnd = 160
For $iPage = $iPageStart To $iPageEnd
    $oDivs = _IETagNameGetCollection($oIE, "div")
    If IsObj($oDivs) Then
        For $oDiv In $oDivs
            If $oDiv.className = "modal-body" Then
                $oLinks = _IETagNameGetCollection($oDiv, "a")
                If IsObj($oLinks) Then
                    For $oLink In $oLinks
                        _ArrayAdd($aLinks, $oLink.innerText & "|" & $oLink.href)
                    Next
                EndIf
            EndIf
        Next
    EndIf
    _IENavigate($oIE, "https://www.uygunparca.com/index.php?route=module/browse/ajax_model&p=59_68&manufacturer_id=13&category_id=68&page=" & $iPage)
    _IELoadWait($oIE)
Next
_ArrayDisplay($aLinks)
Local $oExcel = _Excel_Open()
Local $oWorkbook = _Excel_BookNew($oExcel)
_Excel_RangeWrite($oWorkbook, Default, $aLinks, "A1")

 

Edited by Subz
Link to comment
Share on other sites

4 hours ago, Subz said:

You should look at using IE UDF and Excel UDF much better then using Mouse... and Send functions.  But to loop you just need to use something like:

For $i = 150 To 155
    MsgBox(4096, "", "http://abc.com/" & $i)
Next

Here is how to copy all the links into Excel using IE and Excel UDF.

#include <Array.au3>
#include <Excel.au3>
#include <IE.au3>
Local $aLinks[0][2]
$oIE = _IECreate("https://www.uygunparca.com/index.php?route=module/browse/ajax_model&p=59_68&manufacturer_id=13&category_id=68&page=150", 1)
_IELoadWait($oIE)
Local $iPageStart = 151, $iPageEnd = 160
For $iPage = $iPageStart To $iPageEnd
    $oDivs = _IETagNameGetCollection($oIE, "div")
    If IsObj($oDivs) Then
        For $oDiv In $oDivs
            If $oDiv.className = "modal-body" Then
                $oLinks = _IETagNameGetCollection($oDiv, "a")
                If IsObj($oLinks) Then
                    For $oLink In $oLinks
                        _ArrayAdd($aLinks, $oLink.innerText & "|" & $oLink.href)
                    Next
                EndIf
            EndIf
        Next
    EndIf
    _IENavigate($oIE, "https://www.uygunparca.com/index.php?route=module/browse/ajax_model&p=59_68&manufacturer_id=13&category_id=68&page=" & $iPage)
    _IELoadWait($oIE)
Next
_ArrayDisplay($aLinks)
Local $oExcel = _Excel_Open()
Local $oWorkbook = _Excel_BookNew($oExcel)
_Excel_RangeWrite($oWorkbook, Default, $aLinks, "A1")

 

Thanks Sebzero i got error. Actually every page have 40 categorys i tring to save them to excel that's why i used mouse and functions mouse slecting categorys. I try to explain with photos :) 

Ekran Alıntısı1.JPG

Ekran Alıntısı2.JPG

error.JPG

Link to comment
Share on other sites

Code works fine for me, it copies links from pages 150 to 160.  Please check you have the latest version of Autoit installed, also try running the code via Scite requires Autoit Editor I think (https://www.autoitscript.com/site/autoit-script-editor/downloads/) so you can see when the error occurs via Scites console.  I've also updated the code above so that it writes the links to each cell.  You can still use Send and Mouse commands but they're not the most reliable functions.

Link to comment
Share on other sites

8 hours ago, Subz said:

Code works fine for me, it copies links from pages 150 to 160.  Please check you have the latest version of Autoit installed, also try running the code via Scite requires Autoit Editor I think (https://www.autoitscript.com/site/autoit-script-editor/downloads/) so you can see when the error occurs via Scites console.  I've also updated the code above so that it writes the links to each cell.  You can still use Send and Mouse commands but they're not the most reliable functions.

Yeah your code much much more usefu andl it's perfect. I install final version It's working good now but it's not send any link to anywhere in my computer or not open any excel thing. i check it in editor it's said like that ">"C:\Program Files (x86)\AutoIt3\SciTE\..\autoit3.exe" /ErrorStdOut "C:\Users\DeathLoCk\Desktop\Yeni AutoIt v3 Script (3).au3"    
--> IE.au3 T3.0-2 Warning from function _IEAttach, $_IESTATUS_NoMatch
"C:\Program Files (x86)\AutoIt3\Include\IE.au3" (1812) : ==> The requested action with this object has failed.:
Return SetError($_IESTATUS_Success, $oTemp.GetElementsByTagName($sTagName).length, $oTemp.GetElementsByTagName($sTagName))
Return SetError($_IESTATUS_Success, $oTemp^ ERROR
>Exit code: 1    Time: 27.89"

Link to comment
Share on other sites

Can you please try the following, I'm not sure why the previous code isn't working for you, are you using the script as posted, because I can't replicate the error?  The following code includes an error handler from @mLipok so should continue on error, although if you're using the code as posted you should verify that you see 400 links.

PS: When responding please don't quote me as it makes the post longer than necessary.

#include <Array.au3>
#include <Excel.au3>
#include <IE.au3>
_IEErrorHandlerRegister(_User_ErrFunc)
Local $aLinks[0][2]
Local $oIE = _IECreate("https://www.uygunparca.com/index.php?route=module/browse/ajax_model&p=59_68&manufacturer_id=13&category_id=68&page=150", 1)
_IELoadWait($oIE)
Local $iPageStart = 151, $iPageEnd = 160
For $iPage = $iPageStart To $iPageEnd
    $oDivs = _IETagNameGetCollection($oIE, "div")
    If Not @error Then
        For $oDiv In $oDivs
            If $oDiv.className = "modal-body" Then
                $oLinks = _IETagNameGetCollection($oDiv, "a")
                If Not @error Then
                    For $oLink In $oLinks
                        _ArrayAdd($aLinks, $oLink.innerText & "|" & $oLink.href)
                    Next
                EndIf
            EndIf
        Next
    EndIf
    _IENavigate($oIE, "https://www.uygunparca.com/index.php?route=module/browse/ajax_model&p=59_68&manufacturer_id=13&category_id=68&page=" & $iPage)
    If @error Then ExitLoop MsgBox(4096, "Error:", "Unable to navigate to:" & @CRLF & "https://www.uygunparca.com/index.php?route=module/browse/ajax_model&p=59_68&manufacturer_id=13&category_id=68&page=" & $iPage & @CRLF & @CRLF & "Exiting Loop")
    _IELoadWait($oIE)
Next
_ArrayDisplay($aLinks)
Local $oExcel = _Excel_Open()
Local $oWorkbook = _Excel_BookNew($oExcel)
For $i = 0 To UBound($aLinks) - 1
    _Excel_RangeWrite($oWorkbook, Default, $aLinks[$i][0], "A" & $i)
    _Excel_RangeLinkAddRemove($oWorkbook, Default, "A" & $i, $aLinks[$i][1])
Next

Func _User_ErrFunc($oError)
    ; Do anything here.
    ConsoleWrite(@ScriptFullPath & " (" & $oError.scriptline & ") : ==> COM Error intercepted !" & @CRLF & _
            @TAB & "err.number is: " & @TAB & @TAB & "0x" & Hex($oError.number) & @CRLF & _
            @TAB & "err.windescription:" & @TAB & $oError.windescription & @CRLF & _
            @TAB & "err.description is: " & @TAB & $oError.description & @CRLF & _
            @TAB & "err.source is: " & @TAB & @TAB & $oError.source & @CRLF & _
            @TAB & "err.helpfile is: " & @TAB & $oError.helpfile & @CRLF & _
            @TAB & "err.helpcontext is: " & @TAB & $oError.helpcontext & @CRLF & _
            @TAB & "err.lastdllerror is: " & @TAB & $oError.lastdllerror & @CRLF & _
            @TAB & "err.scriptline is: " & @TAB & $oError.scriptline & @CRLF & _
            @TAB & "err.retcode is: " & @TAB & "0x" & Hex($oError.retcode) & @CRLF & @CRLF)
EndFunc   ;==>_User_ErrFunc

 

Link to comment
Share on other sites

Sorry I don't and at work at the moment.  It looks like your machine isn't handling the script, can you try adding a couple of sleep functions and adjust as required?

Sleep(3000) ;~ Wait 3 Seconds, adjust as required
    _IENavigate($oIE, "https://www.uygunparca.com/index.php?route=module/browse/ajax_model&p=59_68&manufacturer_id=13&category_id=68&page=" & $iPage)
    If @error Then ExitLoop MsgBox(4096, "Error:", "Unable to navigate to:" & @CRLF & "https://www.uygunparca.com/index.php?route=module/browse/ajax_model&p=59_68&manufacturer_id=13&category_id=68&page=" & $iPage & @CRLF & @CRLF & "Exiting Loop")
    _IELoadWait($oIE)
    Sleep(31000) ;~ Wait 3 Seconds, adjust as required

 

Link to comment
Share on other sites

>"C:\Program Files\AutoIt3\SciTE\..\autoit3.exe" /ErrorStdOut "D:\Users\eatalik.BORINTERNAL\Desktop\Yeni AutoIt v3 Script.au3"    
--> IE.au3 T3.0-2 Warning from function _IEAttach, $_IESTATUS_NoMatch
D:\Users\eatalik.BORINTERNAL\Desktop\Yeni AutoIt v3 Script.au3 (1811) : ==> COM Error intercepted !
    err.number is:      0x80020008
    err.windescription: Geçersiz değişken türü.(Invalid variable type)

    err.description is:     
    err.source is:      
    err.helpfile is:    
    err.helpcontext is:     
    err.lastdllerror is:    0
    err.scriptline is:  1811
    err.retcode is:     0x00000000

D:\Users\eatalik.BORINTERNAL\Desktop\Yeni AutoIt v3 Script.au3 (1811) : ==> COM Error intercepted !
    err.number is:      0x80020008
    err.windescription: Geçersiz değişken türü.(Invalid variable type)

    err.description is:     
    err.source is:      
    err.helpfile is:    
    err.helpcontext is:     
    err.lastdllerror is:    0
    err.scriptline is:  1811
    err.retcode is:     0x00000000

D:\Users\eatalik.BORINTERNAL\Desktop\Yeni AutoIt v3 Script.au3 (12) : ==> COM Error intercepted !
    err.number is:      0x000000A9
    err.windescription: Variable is not of type 'Object'.
    err.description is:     
    err.source is:      
    err.helpfile is:    
    err.helpcontext is:     
    err.lastdllerror is:    0
    err.scriptline is:  12
    err.retcode is:     0x00000000

>Exit code: 3221225477    Time: 331.5

@Subz I realize another thing. I try your first code and i make for- next look until 157 it's work very well. Maybe this problem about variable type. Maybe variable can't carry. Because  page 151 to page 157 links are total 280 links when add another page it's getting more big then 256. What do you think abouth that ? Sir i try page 157 to page 163 it's total 280 links too but when i add one more page it's giving error again i'm sure now. 

Edited by website29
Link to comment
Share on other sites

@Subz Yeah i tryed it's same results until 7 page it's no problem working well. After 7 page it's starting give error. Like page 151 to page 157  or page 157 to page 163 it's working well. 

 

@Subz i will get together your codes and my mouse codes with loop. After your code work mouse code will change page numbers after then it will start your code again. What do you think ?

Edited by website29
Link to comment
Share on other sites

@mLipok it's giving this error in that code please help :(

>"C:\Program Files (x86)\AutoIt3\SciTE\..\autoit3.exe" /ErrorStdOut "C:\Users\DeathLoCk\Desktop\Yeni AutoIt v3 Script (4).au3"    
--> IE.au3 T3.0-2 Warning from function _IEAttach, $_IESTATUS_NoMatch
"C:\Program Files (x86)\AutoIt3\Include\IE.au3" (1812) : ==> The requested action with this object has failed.:
Return SetError($_IESTATUS_Success, $oTemp.GetElementsByTagName($sTagName).length, $oTemp.GetElementsByTagName($sTagName))
Return SetError($_IESTATUS_Success, $oTemp^ ERROR
>Exit code: 1    Time: 22.9
#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.3.14.5
 Author:         myName

 Script Function:
    Template AutoIt script.

#ce ----------------------------------------------------------------------------

; Script Start - Add your code below here
#include <Array.au3>
#include <Excel.au3>
#include <IE.au3>
Local $aLinks[0][2]
$oIE = _IECreate("https://www.uygunparca.com/index.php?route=module/browse/ajax_model&p=59_68&manufacturer_id=13&category_id=68&page=150", 1)
_IELoadWait($oIE)
Local $iPageStart = 151, $iPageEnd = 160
For $iPage = $iPageStart To $iPageEnd
    $oDivs = _IETagNameGetCollection($oIE, "div")
    If IsObj($oDivs) Then
        For $oDiv In $oDivs
            If $oDiv.className = "modal-body" Then
                $oLinks = _IETagNameGetCollection($oDiv, "a")
                If IsObj($oLinks) Then
                     For $oLink In $oLinks
                        _ArrayAdd($aLinks, $oLink.innerText & "|" & $oLink.href)
                    Next

                EndIf
            EndIf
        Next
    EndIf
    _IENavigate($oIE, "https://www.uygunparca.com/index.php?route=module/browse/ajax_model&p=59_68&manufacturer_id=13&category_id=68&page=" & $iPage)
    _IELoadWait($oIE)
Next
_ArrayDisplay($aLinks)
Local $oExcel = _Excel_Open()
Local $oWorkbook = _Excel_BookNew($oExcel)
_Excel_RangeWrite($oWorkbook, Default, $aLinks, "A1")

Also it's not giving any error like that but giving empty excel result

include <Array.au3>
#include <Excel.au3>
#include <IE.au3>
Local $aLinks[0][2]
$oIE = _IECreate("https://www.uygunparca.com/index.php?route=module/browse/ajax_model&p=59_68&manufacturer_id=13&category_id=68&page=150", 1)
_IELoadWait($oIE)
Local $iPageStart = 151, $iPageEnd = 160
For $iPage = $iPageStart To $iPageEnd
    $oDivs = _IETagNameGetCollection($oIE, "div")
    If IsObj($oDivs) Then
        For $oDiv In $oDivs
            If $oDiv.className = "modal-body" Then
                $oLinks = _IETagNameGetCollection($oDiv, "a")
                If IsObj($oLinks) Then
                     #cs
                     For $oLink In $oLinks
                        _ArrayAdd($aLinks, $oLink.innerText & "|" & $oLink.href)
                    Next
                    #ce

                EndIf
            EndIf
        Next
    EndIf
    _IENavigate($oIE, "https://www.uygunparca.com/index.php?route=module/browse/ajax_model&p=59_68&manufacturer_id=13&category_id=68&page=" & $iPage)
    _IELoadWait($oIE)
Next
_ArrayDisplay($aLinks)
Local $oExcel = _Excel_Open()
Local $oWorkbook = _Excel_BookNew($oExcel)
_Excel_RangeWrite($oWorkbook, Default, $aLinks, "A1")

 

Edited by website29
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...