gpt4 book ai didi

python - 使用 Selenium Webdriver 从 python 中的下拉列表中选择选项

转载 作者:行者123 更新时间:2023-12-01 04:11:22 27 4
gpt4 key购买 nike

我已经尝试过SELECT类实用程序及其所有功能,包括 selectByVisibleText()和其他人但没有成功。以下是我的元素的 div 层次结构,然后是 <select>我想阅读的框。

<div class="abc">
<div class="def">
<div class="xyz">
<div></div>
<select class="qwe" id="asd">
<option class="zxc" label="test" value="01">01</option>
and options are so on till value 12.

如何在 python 中使用 selenium webdriver 选择选项?

编辑1:我尝试的代码如下:

select = Select(browser.find_element_by_id("asd"))
select.select_by_visible_text('04')

并且,

 eMonth = browser.find_element_by_id("asd")
eMonth.send_keys("10")

最佳答案

您可以使用带有显式等待的 Select

wait = WebDriverWait(driver, 10)
dropDown = wait.until(expected_conditions.visibility_of_element_located((By.ID, 'asd')))
select = Select(dropDown)
select.select_by_value('01')

顺便说一下,selectByVisibleText()是Java语法。

关于python - 使用 Selenium Webdriver 从 python 中的下拉列表中选择选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34903488/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com