python selenium 报错unknown error: cannot focus element 解决办法

登录框由于js限制,定位到元素后无法sendkey ,sendky报错如下:

selenium.common.exceptions.WebDriverException: Message: unknown error: cannot focus element
(Session info: chrome=67.0.3396.87)
(Driver info: chromedriver=2.40.565498 (ea082db3280dd6843ebfb08a625e3eb905c4f5ab),platform=Windows NT 6.1.7601 SP1 x86_64)

但是这个手工是可以输入的,应该用自动化的手段也能输入。解决办法就是是使用selenium 的ActionChains。并结合driver.execute_script使用。完整可执行示例代码如下

from selenium import  webdriver
from selenium.webdriver.common.action_chains import ActionChains
driver=webdriver.Chrome()
driver.maximize_window()
driver.get("https://www.ymgk.com/account/logon.html?backURL")
driver.find_element_by_id("logonenter").click()
name = driver.find_element_by_id("logonmobile1")
actions = ActionChains(driver).move_to_element(name)
driver.execute_script('document.getElementById("logonmobile1").value="13888888888"')

 

迎加入自动化测试交流QQ群:143535941 ,进群问题回答:testway 共同讨论自动化问题

    原文作者:testway
    原文地址: https://www.cnblogs.com/testway/p/9207706.html
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞