无法使用 python selenium 从下拉菜单中获取元素
Unable to get element from dropdown menu using python selenium
我正在尝试从此网站提取信息:http://reportes.sui.gov.co/fabricaReportes/frameSet.jsp?idreporte=acu_com_150
我正在为此目的使用 selenium,但我一直无法找到年份、部门或市政当局的每个元素。
from selenium import webdriver
from selenium.webdriver.support.ui import Select
import time
driver = webdriver.Chrome()
driver.get('http://reportes.sui.gov.co/fabricaReportes/frameSet.jsp?idreporte=acu_com_150')
time.sleep(5)
selectYear = Select(driver.find_element_by_name("acu_com_150.agno"))
我收到以下错误:
NoSuchElementException: no such element: Unable to locate element:
您所在的下拉框位于 iframe
内,需要先切换到 iframe
才能访问该元素。
诱导WebDriverWait()
等待frame_to_be_available_and_switch_to_it
()
诱导WebDriverWait()
等待visibility_of_element_located
()
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
from selenium.webdriver.support.select import Select
driver = webdriver.Chrome()
driver.get("http://reportes.sui.gov.co/fabricaReportes/frameSet.jsp?idreporte=acu_com_150")
WebDriverWait(driver,10).until(EC.frame_to_be_available_and_switch_to_it((By.ID,"header")))
select=Select(WebDriverWait(driver,10).until(EC.visibility_of_element_located((By.NAME,"acu_com_150.agno"))))
select.select_by_value("2018")
我正在尝试从此网站提取信息:http://reportes.sui.gov.co/fabricaReportes/frameSet.jsp?idreporte=acu_com_150
我正在为此目的使用 selenium,但我一直无法找到年份、部门或市政当局的每个元素。
from selenium import webdriver
from selenium.webdriver.support.ui import Select
import time
driver = webdriver.Chrome()
driver.get('http://reportes.sui.gov.co/fabricaReportes/frameSet.jsp?idreporte=acu_com_150')
time.sleep(5)
selectYear = Select(driver.find_element_by_name("acu_com_150.agno"))
我收到以下错误:
NoSuchElementException: no such element: Unable to locate element:
您所在的下拉框位于 iframe
内,需要先切换到 iframe
才能访问该元素。
诱导WebDriverWait()
等待frame_to_be_available_and_switch_to_it
()
诱导WebDriverWait()
等待visibility_of_element_located
()
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
from selenium.webdriver.support.select import Select
driver = webdriver.Chrome()
driver.get("http://reportes.sui.gov.co/fabricaReportes/frameSet.jsp?idreporte=acu_com_150")
WebDriverWait(driver,10).until(EC.frame_to_be_available_and_switch_to_it((By.ID,"header")))
select=Select(WebDriverWait(driver,10).until(EC.visibility_of_element_located((By.NAME,"acu_com_150.agno"))))
select.select_by_value("2018")