Php selenium下拉选项和usgs webportal

Php selenium下拉选项和usgs webportal,php,jquery,python,selenium,drop-down-menu,Php,Jquery,Python,Selenium,Drop Down Menu,我按照下面的指南,在区域下拉菜单下点击非洲西部,使用 我还尝试发送关键字,查看regioncombobox以外的不同容器,看看是否可以将值更改为africa west 该网站是 但是,我不断得到一个错误,selenium找不到元素 selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element: {"method":"xpath","selector":"//select[@id='re

我按照下面的指南,在区域下拉菜单下点击非洲西部,使用

我还尝试发送关键字,查看regioncombobox以外的不同容器,看看是否可以将值更改为africa west

该网站是

但是,我不断得到一个错误,selenium找不到元素

 selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element: {"method":"xpath","selector":"//select[@id='regionCombobox']/option[text()='af-w']"}

单击下拉按钮,显示带有
Africa-West
文本的链接:

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

driver = webdriver.Firefox()
driver.get('http://earlywarning.usgs.gov/adds/downloads/index.php')

# explicitly wait for button to appear
button = WebDriverWait(driver, 10).until(EC.visibility_of_element_located((By.CSS_SELECTOR, "span.custom-combobox > a")))
button.click()

# explicitly wait for "Africa - West" link to appear
africa_west = WebDriverWait(driver, 10).until(EC.visibility_of_element_located((By.LINK_TEXT, "Africa - West")))
africa_west.click()

以下是获取并单击所有下拉按钮的方法:

WebDriverWait(driver, 10).until(EC.visibility_of_element_located((By.CSS_SELECTOR, "span.custom-combobox > a")))

buttons = driver.find_elements_by_css_selector('span.custom-combobox > a')

# region
buttons[0].click()

# product
buttons[1].click()

# period
buttons[2].click()   

当我这样做的时候,我得到了selenium.common.exceptions.NoSuchElementException:Message:找不到元素:{“method”:“css selector”,“selector”:“span.custom-combobox>a”}@BaconDoggie,我想我们应该等待按钮出现——更新了代码,我对selenium是新手,我只是想问你为什么我需要使用css选择器自定义框而不是combobox,然后等待10秒?也非常感谢你,你帮助了我。@BaconDoggie,不客气。问题是您不能在这里使用
Select
类并操作Select->option构造,因为实际的
Select
元素是不可见的。您在屏幕上看到的下拉列表实际上是一个span元素,右边有一个a元素作为“V”按钮。希望这能把事情弄清楚。谢谢你给我解释,这有点道理。我将对其他按钮应用相同的过程,以便自动下载这些文件。
WebDriverWait(driver, 10).until(EC.visibility_of_element_located((By.CSS_SELECTOR, "span.custom-combobox > a")))

buttons = driver.find_elements_by_css_selector('span.custom-combobox > a')

# region
buttons[0].click()

# product
buttons[1].click()

# period
buttons[2].click()