使用 PyAutoGUI 自动点击小程序 - 解决 'pyscreeze' 模块错误
使用 PyAutoGUI 自动点击小程序 - 解决 'pyscreeze' 模块错误
本教程将指导你使用 PyAutoGUI 自动点击小程序,并解决常见错误 'AttributeError: module 'pyscreeze' has no attribute 'locateOnWindow'。
代码示例:
import subprocess
import pyautogui
import time
# 打开桌面上的小程序
subprocess.Popen(r'C:\Users\Administrator\Desktop\国开照片采集工具.lnk')
# 等待小程序打开
time.sleep(5)
# 在打开的小程序中找到并点击'我的照片查询'
my_photos_location = pyautogui.locateOnScreen('my_photos.png')
if my_photos_location:
my_photos_x, my_photos_y = pyautogui.center(my_photos_location)
pyautogui.click(my_photos_x, my_photos_y)
else:
print('未找到'我的照片查询'')
# 等待页面加载
time.sleep(5)
# 在打开的页面中找到并点击'考试照片查询'
exam_photos_location = pyautogui.locateOnScreen('exam_photos.png')
if exam_photos_location:
exam_photos_x, exam_photos_y = pyautogui.center(exam_photos_location)
pyautogui.click(exam_photos_x, exam_photos_y)
else:
print('未找到'考试照片查询'')
解决'pyscreeze'模块错误:
如果运行代码时遇到 'AttributeError: module 'pyscreeze' has no attribute 'locateOnWindow' ' 错误,你需要更新你的 pyscreeze 库。
pip install --upgrade pyscreeze
更新完成后,重新运行你的代码。
原文地址: https://www.cveoy.top/t/topic/bsvL 著作权归作者所有。请勿转载和采集!