我想从下拉菜单中选择所有选项值,但是在选择后者时没有输出。任何想法为什么会这样吗?
HTML代码:
<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")>
答案 0 :(得分:1)
这是因为您正在打印webelement
而不是选项值。
要获取所有选项值,请使用此代码。
dropdown= driver.find_element_by_xpath('//*[@id="cmbSecciones"]')
select_box = Select(dropdown)
for item in select_box.options:
print(item.get_attribute('value'))
或者您可以不使用select
类来打印所有选项
dropdown= driver.find_elements_by_xpath('//*[@id="cmbSecciones"]//option')
for item in dropdown:
print(item.get_attribute('value'))