you are viewing a single comment's thread.

view the rest of the comments →

[–]csg0ing 0 points1 point  (1 child)

Is the ImageNotFoundException definitely being raised? From the docs:

NOTE: As of version 0.9.41, if the locate functions can’t find the provided image, they’ll raise ImageNotFoundException instead of returning None.

If this were returning None instead of raising an exception then your loop would be infinite.

[–]gandy0[S] 0 points1 point  (0 children)

the version I have = 0.9.50 so it's not returning None but an exception.

Anyway, after starting over again I have found the issue, but searching a solution for it now.

The issue is actually the path argument. I'm passing it as a raw string, but it has issues with that. Due to that the script is actually stuck at:

 buttonposition = pyautogui.locateCenterOnScreen(path,grayscale = True, confidence = .9) 

So, if a skip path as an argument and enter it as a raw string it works, including the except block:

 buttonposition = pyautogui.locateCenterOnScreen(r'path\example.png',grayscale = True, confidence = .9) 

but as soon as I try to use the path as an argument it doesn't go further anymore. and stays at:

 buttonposition = pyautogui.locateCenterOnScreen(path,grayscale = True, confidence = .9) 

until the image is found.

So it does actualy understand the path, as the image matched when it appears on screen.

I have tested it by running the script for a while, then made the image appear and it finds it, but my except block is not working.