【问题标题】:Message: element not interactable. Xpath correct消息:元素不可交互。 Xpath 正确
【发布时间】:2021-06-15 20:07:51
【问题描述】:

如何点击?显然我可以用鼠标,一个新的面具出现了。当点击()时出现如下错误。

显然 Xpath 是正确的,实际上它报告了以下代码 =

driver.find_element_by_xpath("//span[@class='example']")
<selenium.webdriver.remote.webelement.WebElement (session="9e25c2b4350ca89b8da611a6dc63ae0c", element="f8dc7d1a-a31a-4fc8-98ec-34ff5a7fa12e")>

此消息错误:

selenium.common.exceptions.ElementNotInteractableException: 消息:元素不可交互

【问题讨论】:

    标签: python selenium webdriver selenium-chromedriver webdriverwait


    【解决方案1】:

    使用WebDriverWait() 并等待element_to_be_clickable()

    WebDriverWait(driver,20).until(EC.element_to_be_clickable((By.XPATH,"//span[@class='example']"))).click()
    

    您需要导入以下库

    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.support import expected_conditions as EC
    from selenium.webdriver.common.by import By
    

    【讨论】:

    • 我尝试后,但元素是可见的。事实上,我使用调试控制台。恐怕是交互问题
    • @lolino :您在使用上述代码时是否遇到同样的错误?
    • Traceback(最近一次调用最后一次):exec(exp, global_vars, local_vars) File "", line 1, in raise TimeoutException(message, screen, stacktrace) selenium.common .exceptions.TimeoutException:消息::(
    • @lolino :似乎元素在页面上不可见。如果我可以看到任何具有隐藏样式的父级,您可以发布 html 或共享 url。
    猜你喜欢
    • 1970-01-01
    • 2023-03-28
    • 2019-04-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多