click()不生效ElementNotInteractable

2021-03-17  本文已影响0人  _karen

python+selenium做UI自动化的时候,定位方式没有错误,但是就是点击不到元素,有以下三种解决方案:

# 使用等待
key = WebDriverWait(web_ui.driver, 20).until(
            expected_conditions.element_to_be_clickable((By.XPATH, '//*[@id="na"]/div[1]/ul/li[8]/div')))
# 点击
key.click()

如果上面两种方式都不行,且第二个报错
selenium.common.exceptions.TimeoutException: Message
那就用第三种方案:

a= self.find_element(xpath="//*[text()='test']")
self.actions.move_to_element(a).perform()
self.driver.execute_script("arguments[0].click();", a)
上一篇 下一篇

猜你喜欢

热点阅读