Reputation: 29
I want to select all the option values from a dropdown menu, but when selecting the latter no output appears. Any ideas why is this happening?
Html Code:
<select class="Combo" id="cmbSecciones" onchange="FiltrarCombos(this,this.item(this.selectedIndex).value);LlenarComboCargo(this,this.item(this.selectedIndex).value)
My code:
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
output:
<selenium.webdriver.remote.webelement.WebElement (session="34e889c18eb0b5f5dbe6a18d6107389e", element="245e4c6a-e564-460e-9dd9-d678c7028c2d")>
Upvotes: 2
Views: 105
Reputation: 33384
This is because you are printing webelement
not the option values.
To get all option values use this code.
dropdown= driver.find_element_by_xpath('//*[@id="cmbSecciones"]')
select_box = Select(dropdown)
for item in select_box.options:
print(item.get_attribute('value'))
Or you can do without select
class to print all options
dropdown= driver.find_elements_by_xpath('//*[@id="cmbSecciones"]//option')
for item in dropdown:
print(item.get_attribute('value'))
Upvotes: 1