Pyautogui For循环跳过

时间:2020-06-23 03:33:24

标签: python pyautogui

我在遍历项目列表并使用pyautogui.write函数从文本框中的每个迭代项目中输入项目时遇到了问题,基本上发生的是,循环有时跳过了两个或三个项目,这是我的代码 这里的name_list参数是实际的名称列表

def send_name(name_list):
    time.sleep(4)
    pyautogui.click(1024,227)
    for name in name_list:
        create_request = pyautogui.click(1195,239)
        time.sleep(1)
        acct = pyautogui.click(1018,392)
        pyautogui.click(1053,427)
        promo_code_box = pyautogui.click(1006,466)
        pyautogui.write(name)
        time.sleep(2) 
        pyautogui.doubleClick(880,436)    
        quantity = pyautogui.click(998,533)
        submit = pyautogui.click(754,577)
        time.sleep(1)
        confirm = pyautogui.click(757,487)
        pyautogui.click(778,245)

例如,如果name_list为['prada','gucci','adidas','nike','puma','dior']-循环将在此处跳过2个项目,而我需要遍历所有列表 谢谢

1 个答案:

答案 0 :(得分:0)

添加更多睡眠语句应确保不跳过:

def send_name(name_list):
    time.sleep(4)
    pyautogui.click(1024,227)
    for name in name_list:
        time.sleep(1)
        create_request = pyautogui.click(1195,239)
        time.sleep(1)
        acct = pyautogui.click(1018,392)
        time.sleep(1)
        pyautogui.click(1053,427)
        time.sleep(1)
        promo_code_box = pyautogui.click(1006,466)
        time.sleep(1)
        pyautogui.write(name)
        time.sleep(2) 
        pyautogui.doubleClick(880,436)
        time.sleep(1)
        quantity = pyautogui.click(998,533)
        time.sleep(1)
        submit = pyautogui.click(754,577)
        time.sleep(1)
        confirm = pyautogui.click(757,487)
        time.sleep(1)
        pyautogui.click(778,245)