这是我的测试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')
msg没有错误,但选项值没有改变?任何人都可以给我一些建议吗?
以此网站为例: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')
答案 0 :(得分:2)
您应该使用.//select
xpath而不是//select
。这将在表格行中找到合适的select
标记。