硒下拉选项和usgs门户网站


selenium drop down options and usgs webportal

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

Selenium-Python-下拉菜单选项值

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support.ui import Select
driver = webdriver.Firefox()
driver.get(usgs_dataportal_ppt)
driver.find_element_by_xpath("//select[@id='regionCombobox']    /option[text()='af-w']").click()

我还尝试过在regioncombox之外的不同容器中发送密钥,看看是否可以将值更改为非洲西部。

该网站http://earlywarning.usgs.gov/adds/downloads/index.php

然而,我一直收到一个错误,硒找不到元素。

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