选择组合框选项 - Ant 选择组合框

时间:2021-02-06 16:38:55

标签: python selenium combobox

我正在开发一个机器人,使用 selenium python 在网站上自动上传视频。在开发过程中,必须选择一个 Combobox 才能继续进行。我使用 select 函数来选择这个组合框选项。但组合不接受这一点,并显示 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>

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

1 个答案:

答案 0 :(得分:0)

您只能对 select 标签使用 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()