【发布时间】:2013-08-08 14:16:03
【问题描述】:
这是我的测试 HTML:
<tr>
<td >
<select>
<option selected="selected" value="0">0</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
</td>
</tr>
和我的代码一样
select_el=driver.find_element_by_xpath("//select")
Select(el_select).select_by_visible_text('1')
没有错误消息,但是选项值没有改变?谁能给我一些建议?
以本网站为例:https://www-01.ibm.com/products/hardware/configurator/americas/bhui/launchNI.wss
driver.get("https://www-01.ibm.com/products/hardware/configurator/americas/bhui/launchNI.wss")
driver.find_element_by_id("modelnumber").send_keys('7383AC1')
driver.find_element_by_name("submit").click()
el_inputs=driver.find_elements_by_name('CID_CONTROL_VideoAdapter_MultiSelect')
FC='A1QU'
for el_input in el_inputs:
el_td=el_input.find_element_by_xpath("..")
if FC in el_td.get_attribute('innerHTML'):
print el_td.get_attribute('innerHTML')
el_tr=el_td.find_element_by_xpath("..")
el_select=el_tr.find_element_by_xpath("//select")
Select(el_select).select_by_visible_text('1')
【问题讨论】:
-
代码看起来正确。您确定页面上没有更多
select元素吗? (如果可能,请提供页面链接) -
我确定 select 是唯一的元素,更新我的问题,新代码可能更有帮助
-
您是否尝试将
el_select=el_tr.find_element_by_xpath("//select")更改为el_select=el_tr.find_element_by_xpath("./td/select")?希望这将确保它找到正确的select element。
标签: python select selenium option