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