Search code examples
pythonwindowspopupscreenshotpyautogui

How to let pyautogui recognize popup windows?


Apparently, pyautogui does not recognize the "real" screen when using the screenshots features.

The following simple code works fine in most cases, but not in all cases. Apparently, some popup windows will not be recognized (e.g. web pages, Javascript(?), or some Windows messages).

import pyautogui

try:
    pyautogui.click('myButtonSomewhereOnTheScreen.png')
    print("Button clicked")
except:
    print("Error: Button not found")

This issue has been raised a few years ago but it was stated that it is a limitation in Pillow. Is there maybe any improvement over the years or does someone maybe know of a workaround or a different approach to include such popup windows?


Solution

  • Normally pyautogui cannot detect pop-ups, and as you mentioned this is a limitation of the Pillow library. In previous versions we could use pyautogui.locateonscreen but this would cause problems and now only works when the program has already started.