ImageSearch issues to check for location of buttons and ensure Chrome Page is loaded before proceeding.

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Anput
Posts: 8
Joined: 16 Oct 2023, 19:48

ImageSearch issues to check for location of buttons and ensure Chrome Page is loaded before proceeding.

Post by Anput » 18 Apr 2024, 10:18

Hello,

I am writing a script to help make my job a little easier as it often involves hundreds of click per account reviewed. Im trying to use ImageSearch to check for the location of a button that gets displaced if a notification appears.

The notification appears at the end of loop so it needs closed every loop. This is to help create a consistent work environment for the script as right now it has a decent chance to fail.

So basically:
If Button is in Location A continue with rest of script
If Button is in Location B Click Left to close notification then proceed with rest of script

Code: Select all

RunPCScript(FileName, FileContents) {
    CoordMode, Mouse, Screen                                ; Set CoordMode to Mouse for MouseClick command
    Loop, Parse, FileContents, `n                            ; Iterate through each line in the FileContents
    {
        if (GetKeyState("Esc", "P"))                            ; Check for the Esc key
            break                                                       ; If ESC is pressed, break the loop
        CurrentLine := A_LoopField                           ; Extract the current line
        Clipboard := % CurrentLine                            ; Store current line to clipboard
        If (Clipboard = "")
            break                                                       ; Exit the loop if clipboard is empty
        Sleep, 10
        Click, left, 2250, 700
        Send, {Home}
        ImageSearch, ix, iy, 3235, 435, 3460, 500, %A_ScriptDir% "\Images\" AccountButton.png
        If (ErrorLevel = 0) {
            Click, Left, 3420, 418                              ; Clicks the X to close the notification if Button is in shifted location
            Sleep, 100
        break
        } Else If (ErrorLevel = 1) {
        Loop {
        Sleep, 100
        ImageSearch, ix, iy, 3235, 375, 3450, 425, %A_ScriptDir% "\Images\" AccountButton.png
        If (ErrorLevel = 0)
            break
            }
        }
        Sleep, 1000
        Click, Left, 3400, 550                                  ; Clicks Add Button
        Sleep, 250
        Click, Left, 2900, 267                                  ; Clicks to open the Entry Field
        Sleep, 250
        Click, Left, 2900, 300                                  ; Clicks the Entry Field
        Sleep, 250
        Send, ^v                                                ; Paste the current line
        Sleep, 10
        Loop                                                    ; Waits for the blue bar to appear to ensure line is correctly selected
        {
            PixelGetColor, color, 1000, 330 
            if (color = 0xB77A33) {
                break
            }
            Sleep, 10
        }                                      
        Send, {Enter}                                           ; Press Enter to add the line to the account
        Sleep, 100
        Click, Left, 3623, 344                                  ; Clicks the Add Button
        Sleep, 250
        Send, {Enter}                                           ; Press Enter to confirm the line will be added
        Sleep, 10
    }
}
Not sure what I did wrong but the image search seems to work but it skips to the line for the "Clicks to open Entry Field". Any help would be appreciated. I would like to add an image search at the bottom of the script to check that the Chrome Tab has finished loading as well but I want to figure out what I did wrong here first. Any help would be appreciated.

Anput
Posts: 8
Joined: 16 Oct 2023, 19:48

Re: ImageSearch issues to check for location of buttons and ensure Chrome Page is loaded before proceeding.

Post by Anput » 18 Apr 2024, 13:03

For now I added the following at the end to check to make sure that Chrome tab is loaded and removed the non-functioning button check for now.

Seems to be working but have to test more to see if it fails. Would still like assistance on getting it to work if possible.

Code: Select all

        ImageSearch, ix, iy, 2910, 7, 3140, 36, %A_ScriptDir% "\Images\" ChromeLoaded.png
        If (ErrorLevel = 2)
            MsgBox, [Error - Could not search for image]
        Else If (ErrorLevel = 1)
            Loop {
                Sleep, 100
                ImageSearch, ix, iy, 2910, 7, 3140, 36, %A_ScriptDir% "\Images\" ChromeLoaded.png
                If (ErrorLevel = 0)
                break
            }
    }
}

Anput
Posts: 8
Joined: 16 Oct 2023, 19:48

Re: ImageSearch issues to check for location of buttons and ensure Chrome Page is loaded before proceeding.

Post by Anput » 18 Apr 2024, 13:35

Ignore my previous snippet of code, I apparently loaded the old version without the image searches when testing :crazy:

I get only the Error Message Box now so back to square 1

garry
Posts: 3852
Joined: 22 Dec 2013, 12:50

Re: ImageSearch issues to check for location of buttons and ensure Chrome Page is loaded before proceeding.

Post by garry » 19 Apr 2024, 09:16

this example from @A_AhkUser , check if website is loaded
;- viewtopic.php?f=76&t=64418

Code: Select all

;- https://www.autohotkey.com/boards/viewtopic.php?f=76&t=64418
;- from user a_ahkuser 
#warn
#NoEnv
setworkingdir,%a_scriptdir%
f1:="https://www.autohotkey.com/boards/viewforum.php?f=28"
run,%f1%
xxa=Shell.Explorer
GUI,4: Add, ActiveX,x0 y0 w0 h0 vWB ,%xxa%
wb.Silent := True
wb.Navigate(F1)
tooltip,Searching .....`n%f1%
while (wb.busy || wb.readyState <> 4)
   sleep, 100
ComObjConnect(wb, {BeforeNavigate2: "onBeforeNavigate2"})
gosub,a1
return
;-------------
a1:
tooltip
gui,4:destroy
msgbox, 262208,URL_LOADED,DONE,3
exitapp
;-------------
onBeforeNavigate2(_p*) { ; BeforeNavigate2 Event (https://docs.microsoft.com/en-us/previous-versions/aa768326(v=vs.85))
	ToolTip,Searching ....
}
;==============================================================

Post Reply

Return to “Ask for Help (v1)”