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



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

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

你只能对选择标签使用选择方法,对于其他标签,你应该遵循正常的点击和等待

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()

相关内容

  • 没有找到相关文章

最新更新