【发布时间】:2017-04-21 11:07:23
【问题描述】:
我想使用 Selenium 和 Python 从选择字段中选择一个选项。
HTML如下:
<select autocomplete="off" class="style_input_item" name="AccountEnable" id="Enable" value="0" onchange="onPageDataChange()">
<option value="0" selected="selected"><script>T("Disabled")</script>Disabled</option>
<option value="1"><script>T("Enabled")</script>Enabled</option>
</select>
我尝试如下:
driver.find_element_by_xpath('//*[@id="Enable"]/option[value="1"]').click()
我收到了那个错误:
selenium.common.exceptions.NoSuchElementException:消息:没有这样的元素:无法找到元素:{"method":"xpath","selector":"//*[@id="Enable"]/option[值="0"]"}
【问题讨论】:
-
Selenium - Python - drop-down menu option value 的可能重复项。接受的答案不是最好的方法。最好的方法是alecxe的答案。另请参阅sqa.stackexchange.com/questions/1355/…。
-
接受的答案不是最好的方法。最好的方法是 alecxe 的答案。另见sqa.stackexchange.com/questions/1355/…。
标签: python-3.x selenium select xpath