简体   繁体   English

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

[英]Pyautogui - click on image: cannot unpack non-iterable NoneType object

I'm writing a script to fill a monthly tax form using pyautogui.我正在编写一个脚本来使用 pyautogui 填写月度税表。

There are 2 images to be clicked on.有 2 张图片可以点击。

Issue问题

I'm getting the following error on the second one:我在第二个中收到以下错误:

PS C:\Users\Rodrigo\OneDrive\Documentos\Python> & 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:\Users\Rodrigo\OneDrive\Documentos\Python\SIFERE\saf.py", line 16, in <module>
    pyautogui.click('SIFERE/agrega_saf.png')
  File "C:\Users\Rodrigo\AppData\Local\Programs\Python\Python310\lib\site-packages\pyautogui\__init__.py", line 598, in wrapper
    returnVal = wrappedFunction(*args, **kwargs)
  File "C:\Users\Rodrigo\AppData\Local\Programs\Python\Python310\lib\site-packages\pyautogui\__init__.py", line 980, in click  
    x, y = _normalizeXYArgs(x, y)
TypeError: cannot unpack non-iterable NoneType object
PS C:\Users\Rodrigo\OneDrive\Documentos\Python> 

Code代码

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')

I've copied that exact same line to another py file and it works, but not on this one.我已经将完全相同的行复制到另一个 py 文件中,它可以工作,但不能在这个文件上工作。

I think you want to locate the given images on your screen.我认为您想在屏幕上找到给定的图像。

Therefor PyAutoGUI has the function locateOnScreen(image) which returns a location .因此 PyAutoGUI 具有返回location的函数locateOnScreen(image) If the image was found, the location is defined otherwise it's None .如果找到图像,则定义位置,否则为None

See also: How to detect an image and click it with pyautogui?另请参阅: 如何检测图像并使用 pyautogui 单击它?

Try to locate the given images first.尝试首先找到给定的图像。 If they were found, then continue with your input.如果找到它们,请继续输入。

Code代码

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()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Pyautogui Image 工作一段时间后不可迭代,TypeError: cannot unpack non-iterable NoneType object - Pyautogui Image non-iterable after working for a while, TypeError: cannot unpack non-iterable NoneType object PyAutoGui TypeError:无法解压不可迭代的NoneType object - PyAutoGui TypeError: cannot unpack non-iterable NoneType object "有人可以向我解释为什么 pyautogui TypeError: cannot unpack non-iterable NoneType object" - Can someone explain to me why pyautogui TypeError: cannot unpack non-iterable NoneType object Python pyautogui bot 工作一段时间后出现TypeError: cannot unpack non-iterable NoneType object 解决方法 - Python pyautogui bot works for some time and then TypeError: cannot unpack non-iterable NoneType object Solution -- TypeError: cannot unpack non-iterable NoneType object - -- TypeError: cannot unpack non-iterable NoneType object 如何修复“无法解压不可迭代的 NoneType 对象”错误 - How to fix "cannot unpack non-iterable NoneType object" error TypeError:无法解压不可迭代的 NoneType 对象 - TypeError: cannot unpack non-iterable NoneType object TypeError:无法解压不可迭代的 NoneType 对象错误 - TypeError: cannot unpack non-iterable NoneType object Error Numpy 抛出 TypeError: cannot unpack non-iterable NoneType object - Numpy throwing TypeError: cannot unpack non-iterable NoneType object Python 错误 - 无法解压不可迭代的 NoneType object - Python error- cannot unpack non-iterable NoneType object
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM