我想從下拉菜單中選擇所有選項(xiàng)值,但選擇后者時(shí)沒有輸出出現(xiàn)。任何想法為什么會(huì)這樣?網(wǎng)頁代碼:<select class="Combo" id="cmbSecciones" onchange="FiltrarCombos(this,this.item(this.selectedIndex).value);LlenarComboCargo(this,this.item(this.selectedIndex).value)我的代碼:driver = webdriver.Chrome('/Users/Administrador/Documents/chromedriver')main_url = 'https://www.justiciacordoba.gob.ar/Estatico/JEL/Escrutinios/ReportesEleccion20190512/default.html'driver.get(main_url)driver.switch_to.frame("topFrame")dropdown= driver.find_element_by_xpath('//*[@id="cmbSecciones"]')dropdown輸出:<selenium.webdriver.remote.webelement.WebElement (session="34e889c18eb0b5f5dbe6a18d6107389e", element="245e4c6a-e564-460e-9dd9-d678c7028c2d")>
1 回答

搖曳的薔薇
TA貢獻(xiàn)1793條經(jīng)驗(yàn) 獲得超6個(gè)贊
這是因?yàn)槟蛴ebelement的不是選項(xiàng)值。
要獲取所有選項(xiàng)值,請(qǐng)使用此代碼。
dropdown= driver.find_element_by_xpath('//*[@id="cmbSecciones"]')
select_box = Select(dropdown)
for item in select_box.options:
print(item.get_attribute('value'))
或者你可以不用select類來打印所有選項(xiàng)
dropdown= driver.find_elements_by_xpath('//*[@id="cmbSecciones"]//option')
for item in dropdown:
print(item.get_attribute('value'))
添加回答
舉報(bào)
0/150
提交
取消