【问题标题】:Select from a dropdown box without using the Select or Option tags: selenium python从下拉框中选择而不使用 Select 或 Option 标签:selenium python
【发布时间】:2018-05-15 15:36:23
【问题描述】:

我正在尝试从网络上的下拉列表中选择一个值,但 HTML 没有任何 Select 或 Option 标记。列表的值在一个表中,而不是嵌入在代码中。我确实有能力在这个框中输入文本,所以我认为一个简单的解决方案就是使用 .sendkeys (如果输入的文本与它工作的下拉选项匹配,则在网页上),但我猜 Python 不会让你这样做那是一个组合框,因为我刚刚得到一个元素不可见错误。我找到了下面的链接,其中包含如何与下拉列表交互的完整细分,但“无选择选项”部分仅包含 Java 和 Ruby 的示例。

下面是下拉框的检查代码。

我有什么选择?

https://sqa.stackexchange.com/questions/12029/how-do-i-work-with-dropdowns-in-selenium-webdriver?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa

<span class="custom-combobox">
    <input title="" class="custom-combobox-input ui-widget ui-widget-content ui-corner-left ui-autocomplete-input" autocomplete="off">
<a tabindex="-1" class="ui-button ui-widget ui-button-icon-only custom-anchor custom-combobox-toggle ui-corner-right" role="button">
<span class="ui-button-icon ui-icon ui-icon-triangle-1-s">
    </span><span class="ui-button-icon-space"> </span></a></span>
    <span class="ui-button-icon-space"> </span>

【问题讨论】:

标签: python html selenium selenium-webdriver drop-down-menu


【解决方案1】:

刚刚为这个烦人的问题找到了一个非常简单的解决方案, 几天来一直在寻找解决它,选择没有选择类的下拉列表

    
    # Find your dropdown element by the following, finds the element in the dropdown named BRA
    Dropdown_Element = driver.find_element(By.XPATH, "//*[text()='BRA']").click()
    
    # Store the ActionChains class inside the actions variable
    actions = ActionChains(driver)
    
    # Click on the element using the click(on_element=)
    actions.click(on_element=Dropdown_Element)
    time.sleep(2)
    actions.perform()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-09-28
    • 2017-09-30
    • 2019-10-18
    • 1970-01-01
    • 2020-07-10
    • 1970-01-01
    • 2019-02-08
    相关资源
    最近更新 更多