這裏是我的測試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'元素嗎? (如果可能,提供鏈接到頁面) – alecxe
我確定select是唯一的元素,更新我的問題,新的代碼可能更有幫助 – Stella
您是否嘗試更改'el_select = el_tr.find_element_by_xpath(「// select」 )'到'el_select = el_tr.find_element_by_xpath(「./ td/select」)'?希望能確保它找到了正確的'select element'。 –