使用python selenium选择下拉菜单时没有输出

使用python selenium选择下拉菜单时没有输出,python,python-3.x,selenium,web-scraping,Python,Python 3.x,Selenium,Web Scraping,我想从下拉菜单中选择所有选项值,但选择后一个选项时,不会显示输出。你知道为什么会这样吗 Html代码: <select class="Combo" id="cmbSecciones" onchange="FiltrarCombos(this,this.item(this.selectedIndex).value);LlenarComboCargo(this,this.item(this.selectedIndex).value) 输出: <selenium.webdriver.re

我想从下拉菜单中选择所有选项值,但选择后一个选项时,不会显示输出。你知道为什么会这样吗

Html代码:

<select class="Combo" id="cmbSecciones" onchange="FiltrarCombos(this,this.item(this.selectedIndex).value);LlenarComboCargo(this,this.item(this.selectedIndex).value)
输出:

<selenium.webdriver.remote.webelement.WebElement (session="34e889c18eb0b5f5dbe6a18d6107389e", element="245e4c6a-e564-460e-9dd9-d678c7028c2d")>

这是因为您打印的是
webelement
而不是选项值

要获取所有选项值,请使用此代码

dropdown= driver.find_element_by_xpath('//*[@id="cmbSecciones"]')
select_box = Select(dropdown)
for item  in select_box.options:
    print(item.get_attribute('value'))
也可以不使用
选择
类来打印所有选项

dropdown= driver.find_elements_by_xpath('//*[@id="cmbSecciones"]//option')
for item  in dropdown:
    print(item.get_attribute('value'))

但问题是,当选择下拉列表(使用find_元素\u by_xpath)时,即使没有出现错误,我也不会得到任何输出。那么就没有什么可选择的了。现在我意识到我在发布问题时可能不太清楚。@EmilioChambouleyron:检查更新的答案是你在找什么?如果没有,请在你原来的帖子中发布你的预期结果。谢谢。
dropdown= driver.find_elements_by_xpath('//*[@id="cmbSecciones"]//option')
for item  in dropdown:
    print(item.get_attribute('value'))