pyautogui: locate function always returns None

I did a screenshot of my screen on mac (entire display) and then cropped a small area. Used those images on the locate function always returns None.

print pyautogui.locate('button.png', 'screengrab.png', grayscale=True)

About this issue

  • Original URL
  • State: open
  • Created 10 years ago
  • Reactions: 1
  • Comments: 31 (8 by maintainers)

Most upvoted comments

I started a new issue (#150) for this feature request, to keep the issues separate

For what it’s worth, I solved this problem for myself in Windows 10 by turning off “Transparency Effects” in Themes and Related Settings => Colors.

I am running on MacOS 10.12 LocateOnScreen() returns None everytime. Tried a few cropped non animated buttons that are clearly on screen when I run. Any help ?

Update : I can get it to locate an image, but not every time. I tried locating the apple logo that is on the left upper side and it could not find it. But if I have the image file open and visible in the middle of the screen it finds it! Also other items that are in the middle of the screen are found.

Got more info on this. If I extract a section of the original screenshot on it’s own PNG and I try to locate it, None is always returned.

If I open the original screenshot in Photoshop and I crop the image and overwrite the initial one without creating a new PNG and then I use it against a copy of the original screenshot then it detects it.

I suspect there is some sort of issue about the profile photoshop uses to save the PNG format even if both are RGB space 8 bit. As the match is exact I guess quality or the image information itself changes when saved by photoshop and it’s no longer the same as in the original screenshot.