I've been using a script to automate a task for about a year now, and it needs updating. This is the script in its unchanged form:
Loop, 770
{
Click, 963 855 ; click position A
Random, DelayValue, 1125, 1175
Sleep DelayValue
Click, 2012 662 ; click position B
Random, DelayValue, 1125, 1175
Sleep, DelayValue
Click, 638, 925 ; clicks the first option for position C
Click, 638, 1005 ; clicks the second option for position C
Random, DelayValue, 1000, 2000
Sleep DelayValue
}
And this worked until the site I was using the script on underwent some visual changes. Positions A and B are unchanged, but now the button at position C can be moved out of position by accompanying text thanks to a font size change.
So I've tried taking a screenshot of the button that's at position C, using ImageSearch to grab its position, defining the x and y it spits out as variables, and changing the position C's click line to use those variables, like so:
ImageSearch, FoundX, FoundY, 0, 0, A_ScreenWidth, A_ScreenHeight, [image file path]
Loop, 770
{
Click, 963 855 ; click position A
Random, DelayValue, 1125, 1175
Sleep DelayValue
Click, 2012 662 ; click position B
Random, DelayValue, 1125, 1175
Sleep, DelayValue
Click, %FoundX%, %FoundY% ; click position C
Random, DelayValue, 1000, 2000 ; trying to account for page refreshing time
Sleep DelayValue
}
What I'm trying to get this script to do now, is to use the position from ImageSearch as position C. I have verified that ImageSearch successfully finds the button. I've checked that MouseMove, MouseClick, and Click all work perfectly fine with %FoundX% and %FoundY%. I have tried putting ImageSearch both inside and outside the loop. But for a reason I simply cannot figure out, there is no cursor movement between the click and position B and the click and position C. Multiple ways of using ImageSearch's output for position C's click have worked outside of this loop. I would really like some help understanding why it's not working inside the loop.
While writing this post, I decided to check if ImageSearch actually does anything while the loop is running, so I added an if (ErrorLevel = 1) check inside the loop, before the step that's meant to click at position C. To add to my confusion, an ImageSearch that functions just fine seems to stop functioning while the loop is running. I'm not sure why.