Susmit
Susmit

Reputation: 394

Python 3.6.3 pyautogui.locateOnScreen not working

I have a "find.png" (attached) The pyautogui.locateOnScreen is returning None, even after 20 screenshots!!!! Using interpreter (code attached) Note: 1) the image having the line, "import pyautogui as auto", is "find.png" 2)I have "find.png" in the same directory, it is founded( checked with PIL- Image) pic contains the line, "import pyautogui as auto" code which is returning, "None"

Upvotes: 1

Views: 15840

Answers (3)

Taohidul Islam
Taohidul Islam

Reputation: 5414

Try this:

location = pyautogui.locateOnScreen('testing.png', confidence =.8)

Upvotes: 5

cabbycapcap
cabbycapcap

Reputation: 126

After struggling with this forever also, finally figured out that you either use command line or print screen button with the windows key to take the screenshot. Using the snipping tool does not work so try:

image = pyautogui.screenshot()
image.save('testing.png')

Go and crop testing.png as small as possible so that locateOnScreen works faster. Then go back to the terminal and type:

pyautogui.locateOnScreen('testing.png')

Upvotes: 11

anurag0510
anurag0510

Reputation: 763

None simply means that PyAutoGui was unable to find your image on the screen, do remember the window is active where find.png was sampled from. If this doesn't work out then I believe the resolutions(from when you took the sample and the monitor used by you) are different. Let us know if you face any problem.

Upvotes: 0

Related Questions