代码之家  ›  专栏  ›  技术社区  ›  Lewis Boxer

pyautogui在屏幕上的位置未找到弹出窗口

  •  0
  • Lewis Boxer  · 技术社区  · 7 年前

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

    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脚本之前屏幕上显示了错误消息,那么这个程序就可以运行了。我甚至给了它一个睡眠计时器,以确保程序正确打开并及时显示消息

    有什么想法吗

    1 回复  |  直到 7 年前
        1
  •  0
  •   Lewis Boxer    7 年前

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

    希望这对其他人有帮助