【问题标题】:error selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable错误 selenium.common.exceptions.ElementNotInteractableException:消息:元素不可交互
【发布时间】:2020-05-25 10:40:30
【问题描述】:

我尝试按元素名称搜索: login_form = driver.find_element_by_name('用户名') login_form.click()

收到此错误:

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

如何解决这个问题?

【问题讨论】:

    标签: selenium


    【解决方案1】:

    您必须在单击该元素之前引入显式等待,直到该元素变为可交互。试试这个:

    login_form = WebDriverWait(driver, 20).until(
    EC.element_to_be_clickable((By.NAME, "username")))
    
    login_form.click();
    

    注意:在您的代码中添加以下导入:

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

    【讨论】:

      【解决方案2】:

      这个错误是由于没有正确找到元素而发生的,因为页面没有正确加载。因此,您可以使用以下任何一种语句给一些时间来加载页面。

      1) time.sleep(10) 2) driver.implicitly_wait(10)

      import time
      
      user_name = "demo.wxyz@gmail.com"
      password = "xyz"
      
      login = driver.find_element_by_id("LoginForm_email")
      loing_passwd = driver.find_element_by_id("LoginForm_password")
      time.sleep(10)
      driver.implicitly_wait(10)
      login.send_keys(user_name)
      login_passwd.send_keys(password)
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-06-10
        • 1970-01-01
        • 2020-08-28
        • 1970-01-01
        • 2019-08-09
        相关资源
        最近更新 更多