【问题标题】:Why has my pyautogui Code stopped locating buttons on the screen?为什么我的 pyautogui 代码停止在屏幕上定位按钮?
【发布时间】:2017-11-19 03:02:51
【问题描述】:

我的程序运行良好,使用 pyautogui.locateOnScreen 定位按钮所在的区域,然后使用 pyautogui.locateCenterOnScreen 显然带有指向正确图像的文件路径来定位按钮的中心。

不过,现在运行它会返回中心和位置的 none 值。

我已经卸载了pyautogui并重新安装它并没有修复它。

我只关注 RecordMP3 代码

这是我的代码

import pyautogui, time
def RecordMP3():
    time.sleep(5)
    RecordMP3 = pyautogui.locateOnScreen("D:/Programming/Python/AutoGUI/Images/SaveButton.PNG")
    print(RecordMP3)
    CenterRecordMP3 = pyautogui.locateCenterOnScreen("D:/Programming/Python/AutoGUI/Images/SaveButton.PNG",region = (RecordMP3))
    print(CenterRecordMP3)  
    pyautogui.click(CenterRecordMP3)

def SaveButton():
    while True:
        counter = 0
        SaveButton = pyautogui.locateOnScreen("D:/Programming/Python/AutoGUI/Images/SaveButton.PNG")
        print("Location",SaveButton)
        SaveButtonCenter = pyautogui.locateCenterOnScreen("D:/Programming/Python/AutoGUI/Images/SaveButton.PNG", region = (SaveButton))
        print("Center",SaveButtonCenter,)
        pyautogui.click(SaveButtonCenter)
        time.sleep=(2)
        counter +=1
        if counter < 10:
            continue
        else:
            break

#print("it worked!!")  
RecordMP3()

这是我搜索的屏幕:

这是我要查找的按钮:

【问题讨论】:

  • 当程序行为发生变化时,记下您所做的可能会影响行为变化的事情非常有帮助。在这里你只是简单地声明"it worked before, now it doesn't",这根本没有用。你更新软件版本了吗?网站布局有变化吗?你改变文件路径了吗?提供指示发生了什么变化的信息对于正确调试是必要的。

标签: python-3.x automation pyautogui


【解决方案1】:

虽然我的建议也有点晚了,但我和许多其他人一样遇到了这个问题。

我已经通过使用 auto-py-to-exe 将 .py 编译成 .exe 解决了这个问题。

希望对你有用。

【讨论】:

    【解决方案2】:

    虽然我的建议有点晚,但我也遇到了这个问题。我已经通过拍摄我正在寻找的图像的另一个屏幕截图来解决这个问题。作为一个友好的提醒,如果图像不是像素完美的,pyautogui 不会找到它。

    希望您找到解决方案!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-06
      • 2019-12-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多