无法从下拉硒中选择项目而未选择

时间:2019-03-09 11:18:18

标签: selenium

我是Python的新手,正在尝试从下拉列表中找出如何调用项目。我设法通过此代码使其可见。 price_point = driver.find_elements_by_class_name(“单选”) price_point [0] .click() 我无法使用“选择”。 该列表已打开并且现在可见,但是我无法单击列表中的项目。有任何想法吗? 非常感谢您的帮助!

1 个答案:

答案 0 :(得分:0)

直接访问列表项,然后单击它。这是示例

driver.find_element_by_xpath("//select[@class='chosen-single']//option[normalize-space(.)='here goes your list item text']").click() 

如果您有多个类别为“选择单个”的列表框,请使用以下内容从第一个列表框中选择项目。

driver.find_element_by_xpath("(//select[@class='chosen-single'])[1]//option[normalize-space(.)='here goes your list item text']").click()