我一直在使用pyautogui自动化一些浏览器内容,如下所示:
time.sleep(1)
locationscs = pyautogui.locateOnScreen('scs.PNG', confidence=.8)
pyautogui.click(locationscs)
time.sleep(1)这并不理想,因为有时页面没有及时加载,我也不会点击。
我试过这样的方法:
r = None
while r is None:
location3 = pyautogui.locateOnScreen('ii.PNG', confidence=.7)
pyautogui.click(location3)这将单击我的元素,但它只是继续单击它。我试着把r设置为不像这样:
r = None
while r is None:
location3 = pyautogui.locateOnScreen('ii.PNG', confidence=.7)
pyautogui.click(location3)
r = not None这不管用,只是毁了我的剧本。无论如何,我有更多的图片要点击之后。我怎么能让pyautogui等待图像1,单击它,然后继续等待图像2,单击,然后图像3,单击?
我试过的是上面的解释。
发布于 2022-11-03 21:02:04
import pyautogui
import time
#for first image
while True:
time.sleep(1) #prevents lag and waits for new image
image1 = pyautogui.locateOnScreen('ii.PNG', confidence=.7)#first image location
if image1: #if the image is found
print('found image clicking...')
pyautogui.click(image1)
break
#for second image
while True:
time.sleep(1) #prevents lag and waits for new image
image2 = pyautogui.locateOnScreen('ii.PNG', confidence=.7) #second image
if image2: #if the image is found
print('found image clicking...')
pyautogui.click(image2)
break
#and so onhttps://stackoverflow.com/questions/74289379
复制相似问题