m0_50541896 2021-11-08 07:32 采纳率: 100%
浏览 40
已结题

python-selenium中ActionChain行为链中报错问题

就挺奇怪的,这个代码是一个课程中的代码,一模一样,复制来的,为什么到我的电脑就报错

img


然后我也在论坛找了一下这个错误有些说是代码运行速度比网页加载速度快,我在每行代码中间都沉睡1s还是没用,而且元素看过了没有过期这是代码**
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains

driver = webdriver.Chrome(executable_path=r'C:\chromedriver\bin\chromedriver.exe')

driver.get("

)

actions = ActionChains(driver)
usernameTag = driver.find_element_by_name("username")
passwordTag = driver.find_element_by_name("password")
submitBtn = driver.find_element_by_class_name("SignFlow-submitButton")

actions.move_to_element(usernameTag)
actions.send_keys_to_element(usernameTag,"18888888888")
actions.move_to_element(passwordTag)
actions.send_keys_to_element(passwordTag,"xxxxxx")
actions.move_to_element(submitBtn)
actions.click(submitBtn)

actions.perform()

**

  • 写回答

2条回答 默认 最新

  • zljun8210 2021-11-08 09:33
    关注

    可以从两个方面优化:
    1、 driver.get()语句后加延时,如

     time.sleep(3)
    
    

    2、 用户名和密码的输入分开,如

        actions.move_to_element(usernameTag).sekd_keys_to_element(usernameTag,"188888888").perform()
        time.sleep(1)
        actions.move_to_element(passwordTag).send_keys_to_element(passwordTag,"xxxxxx").perform()
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 11月16日
  • 已采纳回答 11月8日
  • 创建了问题 11月8日

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度