下拉框结构如下,我需要选择的是new:
html为:
<select id="condition_type" name="condition_type" class="notification-required notification-required-unknown">
<option value="">
- Select -</option>
<option value="new, new">
New</option>
<option value="used, like_new">
Used - Like New</option>
<option value="used, very_good">
Used - Very Good</option>
<option value="used, good">
Used - Good</option>
<option value="used, acceptable">
Used - Acceptable</option>
<option value="refurbished, refurbished">
Refurbished</option>
</select>
代码:
from selenium.webdriver.support.select import Select
# 定位到下拉框,选择new
sel = browser.find_element_by_xpath("//select[@id='condition_type']")
Select(sel).select_by_value('new, new')