Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/276.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用selenium python从下拉选项中选择值_Python_Selenium - Fatal编程技术网

使用selenium python从下拉选项中选择值

使用selenium python从下拉选项中选择值,python,selenium,Python,Selenium,我想从下拉选项中选择一个值。html格式如下: <span id="searchTypeFormElementsStd"> <label for="numReturnSelect"></label> <select id="numReturnSelect" name="numReturnSelect"> <option value="200"></option> <op

我想从下拉选项中选择一个值。html格式如下:

<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()

怎么了?请帮帮我

Adrian Ratnapala是对的,而且我会选择
id
而不是
name
,因此您可以尝试以下方法:

find_element_by_xpath("//select[@id='numReturnSelect']/option[@value='15000']").click()

您可以使用:

单击此处了解有关的更多信息


它可以正常工作

也许您需要
@value
,而不是
text()
?我的xpath foo太弱,无法确定。在Python中不确定。但希望您有一个与Java中的Select类类似的Select模块出现以下错误:\n无效SelectorError第一个模块正常工作,但我没有尝试第二个模块。谢谢顺便说一句,你做了什么魔术?哈哈哈,这不是魔术,
选项[text()=“15000']
将检查任何选项标记是否有文本
15000
,但在你的情况下
15000
是值属性。不管怎样,很高兴它有帮助!我建议你也玩一下第二个和第三个,这将帮助你探索selenium。我希望你也能回答我的新问题:这是一个网页,只是通过CSS查找
find_element_by_css_selector("select#numReturnSelect > option[value='15000']").click()
Select(driver.find_element_by_css_selector("select#numReturnSelect")).select_by_value(15000).click()
from selenium.webdriver.support.ui import Select
driver = webdriver.Ie(".\\IEDriverServer.exe")
driver.get("https://test.com")
select = Select(driver.find_element_by_xpath("""//input[@name='n_name']"""))
select.select_by_index(2)
select.select_by_visible_text('Visible Text')
select.select_by_value('value')