下拉列表中的选择值

时间:2020-10-07 20:08:11

标签: selenium select xpath dropdown

我在python上使用硒并尝试在下拉列表中选择一个值,但是我找不到该值的xpath。第二张图片是我手动选择值五时的外观。有人可以帮我点击下拉列表中的某个值吗?

这是可用的xpath。enter image description here enter image description here

1 个答案:

答案 0 :(得分:0)

如果您知道这些值,则使用Select(选择)将更可靠:

from selenium.webdriver.support.ui import Select

select = Select(driver.find_element_by_name('select2-selection'))
select.select_by_visible_text("Item 1")

还有

select.select_by_index(index)
select.select_by_value(value)

您可以尝试。

相关问题