我想从下拉选项中选择一个值.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
Run Code Online (Sandbox Code Playgroud)
我尝试如下:
find_element_by_xpath("//select[@name='numReturnSelect']/option[text()='15000']").click()
Run Code Online (Sandbox Code Playgroud)
这有什么问题?请帮我!
Ami*_*ith 43
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()
Run Code Online (Sandbox Code Playgroud)
OR
find_element_by_css_selector("select#numReturnSelect > option[value='15000']").click()
Run Code Online (Sandbox Code Playgroud)
OR
you can use select_by_value(value) :
Select(driver.find_element_by_css_selector("select#numReturnSelect")).select_by_value(15000).click()
Run Code Online (Sandbox Code Playgroud)
Click here for more info on Select.
小智 5
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')
Run Code Online (Sandbox Code Playgroud)
它会工作正常
| 归档时间: |
|
| 查看次数: |
49587 次 |
| 最近记录: |