[英]Unable to select element by xpath from dropdown menu with Selenium in Python
[英]Unable to get element from dropdown menu using python selenium
我試圖從這個網站提取信息: http : //reportes.sui.gov.co/fabricaReportes/frameSet.jsp?idreporte=acu_com_150
我為此目的使用硒,但我無法找到年份、部門或市政當局的每個元素。
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
()
Induce 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")
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.