gpt4 book ai didi

php - Selenium 下拉选项和 USGS 门户网站

转载 作者:太空宇宙 更新时间:2023-11-03 17:54:57 26 4
gpt4 key购买 nike

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

Selenium - Python - drop-down menu option value

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

我还尝试发送 key 查看除regioncombobox之外的不同容器,看看是否可以将值更改为非洲西部。

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

但是我不断收到错误,selenium 找不到该元素。

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

最佳答案

单击下拉按钮并 wait要显示带有 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()

关于php - Selenium 下拉选项和 USGS 门户网站,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28613079/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com