pyautogui locateonscreen 找不到弹出窗口

pyautogui locateonscreen not finding pop up

我正在尝试使程序自动化,我们一直在使用:

import pyautogui, time
import PIL

input("Press Enter to start")
print("Starting program in 5 seconds")
time.sleep(5)

#open edgewise
pyautogui.hotkey("win")
pyautogui.typewrite("edgewise")
pyautogui.hotkey("Enter")

time.sleep(20)

print("Checking for error message")
a = pyautogui.locateOnScreen("ok.png")
while True:
    if a == None:
        print("Not Found")
        break
    else:
        print("Found")
        new0 = a[0]
        new0 = new0 + 10
        new1 = a[1]
        new1 = new1 + 10
        pyautogui.moveTo(new0,new1,duration=1)
        pyautogui.click()
        break

input("Finished")

所以这个程序的想法是打开软件,在启动过程中它会弹出一条错误消息(有时),要求您单击确定。

现在,如果程序(edgewise)已经启动并且错误消息在我启动 python 脚本之前出现在屏幕上,则该程序可以运行。我什至给了它一个睡眠定时器,以确保程序已正确打开并及时显示消息

任何想法

PYAutoGUI locateonscreen 函数似乎只在程序已经启动时才起作用,我试图构建我的脚本来完成包括启动应用程序在内的所有事情,但这会导致问题。

希望这对其他人有帮助