Python+Selenium之cannot focus element 解决方法

有时候刚进入页面输入第一个值时脚本会报错:cannot focus element

贴下我的脚本和解决办法供大家参考

我原本的脚本是:

WebDriverWait(driver,15,0.5).until(EC.visibility_of_element_located((By.ID,"inputCtrl0"))).send_keys(“Company”)

改为如下操作后就没有报错了:

WebDriverWait(driver,15,0.5).until(EC.visibility_of_element_located((By.ID,"inputCtrl0"))).click()
ActionChains(driver).click(driver.find_element_by_id("inputCtrl0")).send_keys(“Company”).perform()

注意用perform()方法记得导入 from selenium.webdriver.common.action_chains import ActionChains

posted on 2019-04-04 17:16  Amy_Hu  阅读(1472)  评论(0编辑  收藏  举报