zoukankan      html  css  js  c++  java
  • selenium报错“ElementNotInteractableException: Message: element not interactable: Element is not currently visible”

    1、源代码:

    from selenium import webdriver
    import time as t
    from selenium.webdriver.support.select import Select
    from selenium.webdriver.common.keys import Keys
    from selenium.webdriver.common.action_chains import ActionChains
    from selenium.webdriver.support.wait import WebDriverWait
    from selenium.webdriver.support import expected_conditions as ec
    from selenium.webdriver.common.by import By
    
    
    driver = webdriver.Chrome()
    driver.maximize_window()
    driver.get("http://www.baidu.com")
    t.sleep(3)
    driver.find_element_by_id("kw").send_keys("selenium")
    driver.find_element_by_id("su").send_keys(Keys.ENTER)
    # 显式等待,待元素定位
    WebDriverWait(driver,10).until(ec.presence_of_element_located((By.ID,"kw")))
    # 鼠标悬停
    mouse = driver.find_element_by_name("tj_settingicon")
    ActionChains(driver).move_to_element(mouse).perform()
    driver.find_element_by_link_text("搜索设置").click()
    # 隐式等待
    driver.implicitly_wait(5)
    # 定位下拉框
    select = driver.find_element_by_name("NR")
    # # 以索引的方式定位
    # Select(select).select_by_index(2)
    # print("下拉框选择的最新条数是:",select.get_attribute('value'))
    # 以value定位
    # Select(select).select_by_value("10")
    # print("下拉框选择的最新条数是:",select.get_attribute('value'))
    # 以文本定位
    Select(select).select_by_visible_text("每页显示20条")
    print("下拉框选择的最新条数是:",select.get_attribute('value'))
    t.sleep(3)
    driver.quit()
    

    报错:“ElementNotInteractableException: Message: element not interactable: Element is not currently visible”意思是元素隐藏不可见

    百度了很多方法,但是都没有解决此问题

    加了sleep(3),然后就ok了

    再取消sleep,也没有报错了

  • 相关阅读:
    自定义组件要加@click方法
    绑定样式
    647. Palindromic Substrings
    215. Kth Largest Element in an Array
    448. Find All Numbers Disappeared in an Array
    287. Find the Duplicate Number
    283. Move Zeroes
    234. Palindrome Linked List
    202. Happy Number
    217. Contains Duplicate
  • 原文地址:https://www.cnblogs.com/yuer02/p/12625053.html
Copyright © 2011-2022 走看看