首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使pyautogui等待图像出现,然后在图像出现并完成操作后,等待下一个图像的出现。

如何使pyautogui等待图像出现,然后在图像出现并完成操作后,等待下一个图像的出现。
EN

Stack Overflow用户
提问于 2022-11-02 12:46:02
回答 1查看 29关注 0票数 0

我一直在使用pyautogui自动化一些浏览器内容,如下所示:

代码语言:javascript
复制
        time.sleep(1)
        locationscs = pyautogui.locateOnScreen('scs.PNG', confidence=.8)
        pyautogui.click(locationscs)
        time.sleep(1)

这并不理想,因为有时页面没有及时加载,我也不会点击。

我试过这样的方法:

代码语言:javascript
复制
        r = None
        while r is None:
            location3 = pyautogui.locateOnScreen('ii.PNG', confidence=.7)
            pyautogui.click(location3)

这将单击我的元素,但它只是继续单击它。我试着把r设置为不像这样:

代码语言:javascript
复制
        r = None
        while r is None:
            location3 = pyautogui.locateOnScreen('ii.PNG', confidence=.7)
            pyautogui.click(location3)
            r = not None

这不管用,只是毁了我的剧本。无论如何,我有更多的图片要点击之后。我怎么能让pyautogui等待图像1,单击它,然后继续等待图像2,单击,然后图像3,单击?

我试过的是上面的解释。

EN

回答 1

Stack Overflow用户

发布于 2022-11-03 21:02:04

代码语言:javascript
复制
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 on
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/74289379

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档