Pyautogui -单击图像:无法解压缩不可迭代的NoneType对象



我正在编写一个脚本,使用pyautogui填写每月的纳税表格。

有2张图片可供点击。

问题我得到以下错误在第二个:

PS C:UsersRodrigoOneDriveDocumentosPython> & C:/Users/Rodrigo/AppData/Local/Programs/Python/Python310/python.exe c:/Users/Rodrigo/OneDrive/Documentos/Python/SIFERE/saf.py
Traceback (most recent call last):
File "c:UsersRodrigoOneDriveDocumentosPythonSIFEREsaf.py", line 16, in <module>
pyautogui.click('SIFERE/agrega_saf.png')
File "C:UsersRodrigoAppDataLocalProgramsPythonPython310libsite-packagespyautogui__init__.py", line 598, in wrapper
returnVal = wrappedFunction(*args, **kwargs)
File "C:UsersRodrigoAppDataLocalProgramsPythonPython310libsite-packagespyautogui__init__.py", line 980, in click  
x, y = _normalizeXYArgs(x, y)
TypeError: cannot unpack non-iterable NoneType object
PS C:UsersRodrigoOneDriveDocumentosPython> 

代码
import pyautogui, time
time.sleep(3)
anio='2015' 
mes='abril'
secuencia='1'
monto='1234.56'
pyautogui.click('SIFERE/periodo.png')
pyautogui.press('tab')  
pyautogui.write(anio)
pyautogui.press('tab')  
pyautogui.write(mes)
pyautogui.press('tab')  
pyautogui.write(secuencia)
pyautogui.press('tab')  
pyautogui.write(monto)
pyautogui.click('SIFERE/agrega_saf.png')

我已经将相同的行复制到另一个py文件中,它可以工作,但不是在这个文件中。

我想你想在屏幕上找到给定的图像。

因此PyAutoGUI有函数locateOnScreen(image)返回一个location。如果找到图像,则定义位置,否则为None

参见:如何使用pyautogui检测图像并单击它?

尝试先定位给定的图像。如果找到了,则继续输入。

代码
import pyautogui, time
anio='2015' 
mes='abril'
secuencia='1'
monto='1234.56'

def find_image_or_exit(image):
i = 1
while location == None and i < 3:  # try max 3 times (for 9 seconds)
time.sleep(3)  # wait 3 seconds
location = pyautogui.locateOnScreen(image)
i += 1
if location == None:
print(f"Sorry! Image {image} not found on screen. Aborting!")
exit()
return location

def enter_period():
location = find_image_or_exit('SIFERE/periodo.png')
pyautogui.click(location)
pyautogui.press('tab')  
pyautogui.write(anio)
pyautogui.press('tab')  
pyautogui.write(mes)
pyautogui.press('tab')
pyautogui.write(secuencia)
pyautogui.press('tab')  
pyautogui.write(monto)

def add_saf():
location = find_image_or_exit('SIFERE/agrega_saf.png')
pyautogui.click(location)

# main steps
enter_period()
add_saf()

相关内容

  • 没有找到相关文章

最新更新