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,也没有报错了

  • 相关阅读:
    poj 3277 City Horizon (线段树 扫描线 矩形面积并)
    HDU 1255 覆盖的面积 (扫描线 线段树 离散化 矩形面积并)
    Codeforces Round #260 (Div. 2)
    poj 1151 Atlantis (离散化 + 扫描线 + 线段树 矩形面积并)
    CF1237F Balanced Domino Placements
    CF954H Path Counting
    AT2395 [ARC071C] TrBBnsformBBtion
    AT2400 [ARC072B] Alice&Brown
    AT2401 [ARC072C] Alice in linear land
    [国家集训队]阿狸和桃子的游戏
  • 原文地址:https://www.cnblogs.com/yuer02/p/12625053.html
Copyright © 2011-2022 走看看