2

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")> 

    1 Answer 1

    1

    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')) 
    2
    • but the problem is that when selecting the dropdown (with find_element_by_xpath) even though no error arises, I dont get any output. So then there is nothing to select. Now I realize that I may not have been clear when posting the problem.CommentedMay 14, 2020 at 18:49
    • @EmilioChambouleyron : Check updated answer is that you are after? If not then please post your expected out in your original post.Thanks.
      – KunduK
      CommentedMay 14, 2020 at 19:41

    Start asking to get answers

    Find the answer to your question by asking.

    Ask question

    Explore related questions

    See similar questions with these tags.