Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/302.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 选择使用Selenium输入的下拉菜单_Python_Selenium_Web Scraping_Selenium Chromedriver - Fatal编程技术网

Python 选择使用Selenium输入的下拉菜单

Python 选择使用Selenium输入的下拉菜单,python,selenium,web-scraping,selenium-chromedriver,Python,Selenium,Web Scraping,Selenium Chromedriver,我试图在此网页的下拉菜单中选择一年: 我正在使用Select,但它不起作用: Select(driver.find_element_by_xpath('//*[@id="FormListado1:cmd_vc_distcomboboxButton"]')) 它有下一个错误:Select仅对元素有效,而对无效。您知道如何选择此输入元素吗?这不是选择而不是输入元素,因此要打开下拉菜单,您可以使用以下选项: driver.find_element_by_xpath('//inpu

我试图在此网页的下拉菜单中选择一年: 我正在使用Select,但它不起作用:

Select(driver.find_element_by_xpath('//*[@id="FormListado1:cmd_vc_distcomboboxButton"]'))

它有下一个错误:
Select仅对元素有效,而对
无效。您知道如何选择此输入元素吗?

这不是选择而不是输入元素,因此要打开下拉菜单,您可以使用以下选项:

driver.find_element_by_xpath('//input[contains(@id,"PrimeraNormalcomboboxButton")]').click()
现在,您可以从打开的菜单中选择任何项目,如下所示:

driver.find_element_by_xpath('//span[@class="rich-combobox-item" and text()="2015"]').click()
只需使用正确的年份值。
不要忘记添加等待/延迟