用selenium可以定位到一个元素,但是click()报错,在界面可以点击该元素。代码报错为:selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable

排查问题思路

1.确定能定位到元素

python-selenium元素操作,定位到元素报错selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable

 

 2.判断元素是否可以点击

#判断元素是否可以点击
#利用显示等待
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

driver = webdriver.Chrome()

driver.get("http://somedomain/url_that_delays_loading")

#判断元素是否可以点击
def isclickable(xpath):
    try:
        WebDriverWait(driver, 10).until(
            EC.element_to_be_clickable((By.XPATH, xpath)))
        return True
    except :
        return False

  结果返回是false

解决办法:

改变定位的元素。

报错时定位的是svg元素,改为定位button元素后不报错

python-selenium元素操作,定位到元素报错selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable

 

相关文章:

  • 2022-12-23
  • 2022-03-01
  • 2022-12-23
  • 2021-12-10
  • 2021-06-19
  • 2022-12-23
  • 2019-03-22
  • 2021-09-28
猜你喜欢
  • 2021-07-21
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-04-30
相关资源
相似解决方案