使用 selenium python 从下拉选项中选择一个值 [英] Selecting a value from a drop-down option using selenium python
本文介绍了使用 selenium python 从下拉选项中选择一个值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想从下拉选项中选择一个值.html如下:
I want to select a value from a drop-down option. The html is as follows:
<span id="searchTypeFormElementsStd">
<label for="numReturnSelect"></label>
<select id="numReturnSelect" name="numReturnSelect">
<option value="200"></option>
<option value="250"></option>
<option value="500"></option>
<option selected="" value="200"></option>
<option value="800"></option>
<option value="15000"></option>
<option value="85000"></option>
</select>
</span
我尝试如下:
find_element_by_xpath("//select[@name='numReturnSelect']/option[text()='15000']").click()
有什么问题吗?请帮帮我!
What is wrong with it? Please help me!
推荐答案
Adrian Ratnapala 是对的,而且我会选择 id
而不是 name
,因此您可以尝试以下操作:
Adrian Ratnapala is right and also i would choose id
over name
, so you can try the following :
find_element_by_xpath("//select[@id='numReturnSelect']/option[@value='15000']").click()
或
find_element_by_css_selector("select#numReturnSelect > option[value='15000']").click()
或
您可以使用 select_by_value(value)
:
you can use select_by_value(value)
:
Select(driver.find_element_by_css_selector("select#numReturnSelect")).select_by_value(15000).click()
单击此处了解有关 的更多信息选择
.
Click here for more info on Select
.
这篇关于使用 selenium python 从下拉选项中选择一个值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文