【问题标题】:Select the Combobox options - Ant Select Combo box选择 Combobox 选项 - Ant Select Combo box
【发布时间】:2021-02-06 16:38:55
【问题描述】:

我正在开发一个机器人来使用 selenium python 在网站上自动上传视频。在开发过程中,必须选择一个组合框才能继续进行。我使用了选择功能来选择这个组合框选项。但组合不接受这一点,并显示 div 不会接受选择功能。组合框的 HTML 代码:我在 HTML 代码中也找不到选项。

<div class="ant-select-selection
        ant-select-selection--single" role="combobox" aria-autocomplete="list" aria-haspopup="true" aria-controls="96c82e35-7e56-473d-a6ee-9ff4e1352d77" aria-expanded="false" tabindex="0">
<div class="ant-select-selection__rendered">
    <div unselectable="on" class="ant-select-selection__placeholder" style="display: block; user-select: none;">Genre</div>
    <div class="ant-select-search ant-select-search--inline" style="display: none;">
        <div class="ant-select-search__field__wrap">
            <input autocomplete="off" class="ant-select-search__field" value="">
                <span class="ant-select-search__field__mirror">&nbsp;</span>
            </div>
        </div>
    </div>
    <span class="ant-select-arrow" unselectable="on" style="user-select: none;">
        <i aria-label="icon: down" class="anticon anticon-down ant-select-arrow-icon">
            <svg viewBox="64 64 896 896" focusable="false" class="" data-icon="down" width="1em" height="1em" fill="currentColor" aria-hidden="true">
                <path d="M884 256h-75c-5.1 0-9.9 2.5-12.9 6.6L512 654.2 227.9 262.6c-3-4.1-7.8-6.6-12.9-6.6h-75c-6.5 0-10.3 7.4-6.5 12.7l352.6 486.1c12.8 17.6 39 17.6 51.7 0l352.6-486.1c3.9-5.3.1-12.7-6.4-12.7z"></path>
            </svg>
        </i>
    </span>
</div>

有没有办法选择上面代码中的选项?

【问题讨论】:

    标签: python selenium combobox


    【解决方案1】:

    选择标签只能使用 selct 方法,其他标签需要正常点击等待

    driver.find_element_by_xpath('//div[@class="ant-select-selection ant-select-selection--single" and @role="combobox"]//input').click()
    
    driver.find_element_by_xpath('//div[@class="ant-select-selection ant-select-selection--single" and @role="combobox"]//input').send_keys("something")
    
    
    WebDriverWait(driver,10).until(EC.presence_of_element_located((By.XPATH, "//*[contains(text(),'something')]"))).click()
    

    【讨论】:

    • 如何在&lt;div&gt; 上调用send_keys()?
    • @DebanjanB 更新了答案它只是一个示例如何使用它,将其更改为输入标签
    • 但是&lt;input&gt;标签在它的祖先&lt;div&gt;中,有style="display: none;"
    • 不显示不会使其无法交互
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-09-02
    • 1970-01-01
    • 2018-02-03
    • 1970-01-01
    • 2016-08-19
    • 1970-01-01
    • 2019-02-05
    相关资源
    最近更新 更多