Python 如何等待pyautogui.locateonscreen()返回值?
我正在创建一个webbot,我想等待某个图像出现在网页上,然后再继续我的脚本 我正在使用pyautogui.locatesonscreen()函数,但在对象出现之前,我找不到一种方法来定位它Python 如何等待pyautogui.locateonscreen()返回值?,python,pyautogui,Python,Pyautogui,我正在创建一个webbot,我想等待某个图像出现在网页上,然后再继续我的脚本 我正在使用pyautogui.locatesonscreen()函数,但在对象出现之前,我找不到一种方法来定位它 我的脚本似乎只是在返回值none之前运行locateonscreen函数一次-我希望它一直循环,直到找到图像。您可以循环脚本: import pyautogui image = pyautogui.locateOnScreen("image.png") #Searches for the image wh
我的脚本似乎只是在返回值none之前运行locateonscreen函数一次-我希望它一直循环,直到找到图像。您可以循环脚本:
import pyautogui
image = pyautogui.locateOnScreen("image.png")
#Searches for the image
while image == None:
image = pyautogui.locateOnScreen("image.png")
print("still haven't found the image")
#When program finds image, print the location
print(image)
您可以循环脚本:
import pyautogui
image = pyautogui.locateOnScreen("image.png")
#Searches for the image
while image == None:
image = pyautogui.locateOnScreen("image.png")
print("still haven't found the image")
#When program finds image, print the location
print(image)
我知道这篇文章已经有两年了,但我发现这篇文章提出了同样的问题,并且提供的解决方案不适用于pyautogui v0.9.41及更高版本。这是我自己的:
import pyautogui
location = None
imageFile = 'image.png'
while (location == None):
try:
location = pyautogui.locateOnScreen(imageFile)
except Exception as e:
print(e)
print(location)
发件人:
注意:从版本0.9.41开始,如果定位函数找不到提供的映像,它们将引发ImageNotFoundException而不是返回None。我知道这篇文章已经有两年了,但我发现它提出了相同的问题,并且提供的解决方案不适用于pyautogui v0.9.41及更高版本。这是我自己的:
import pyautogui
location = None
imageFile = 'image.png'
while (location == None):
try:
location = pyautogui.locateOnScreen(imageFile)
except Exception as e:
print(e)
print(location)
发件人:
注意:从版本0.9.41开始,如果定位函数找不到提供的映像,它们将引发ImageNotFoundException,而不是返回None