【问题标题】:How to fix, Element <option> could not be scrolled into view error python selenium [duplicate]如何修复,元素 <option> 无法滚动到视图错误 python selenium [重复]
【发布时间】:2019-01-17 23:22:53
【问题描述】:

以下链接中的网页截图:

我正在尝试在选择元素中选择一个选项标签,但我收到一条错误消息,提示元素无法滚动到视图中。

selenium.common.exceptions.ElementNotVisibleException: Message: element not interactable: Element is not currently visible and may not be manipulated (Session info: chrome=71.0.3578.98)

代码:

dropdown = Select(driver.find_element_by_id("motes"))
dropdown.select_by_value("ALDERSHOT [Aldershot]")

【问题讨论】:

    标签: python selenium selenium-webdriver selenium-chromedriver


    【解决方案1】:

    你的代码应该是

    dropdown = Select(driver.find_element_by_id("motes"))
    dropdown.select_by_visible_text("ALDERSHOT [Aldershot]")
    

    有三种方法可以从下拉列表中选择一个选项。

    • dropdown.select_by_index(1) - 使用选项的索引,从 1 开始

    • dropdown.select_by_value("") - 使用选项的值,即文本 html属性'值'

    • dropdown.select_by_visible_text("") - 使用可见文本

    例如,如果您要选择“ACOMB - ELEC [York Acomb]”

    dropdown = Select(driver.find_element_by_id("motes"))
    dropdown.select_by_index(4)
    dropdown.select_by_visible_text("ACOMB - ELEC [York Acomb]")
    dropdown.select_by_value("433372-#42454c")
    

    注意:ALDERSHOT [Aldershot] 选项的值隐藏在屏幕截图中,因此使用了替代选项。

    【讨论】:

    • 已经尝试过了,但我收到以下错误:selenium.common.exceptions.ElementNotVisibleException:消息:元素不可交互:元素当前不可见,可能无法操作(会话信息:chrome=71.0 .3578.98)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-08-15
    • 2019-09-24
    • 2019-09-28
    • 2019-05-28
    • 2019-03-25
    • 2018-08-09
    • 1970-01-01
    相关资源
    最近更新 更多