简体   繁体   中英

Unable to get element from dropdown menu using python selenium

I am trying to extract the information from this website: http://reportes.sui.gov.co/fabricaReportes/frameSet.jsp?idreporte=acu_com_150

I am using selenium for that purpose but I have been unable to locate each element of year, department or municipality.

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

I get the following error:

NoSuchElementException: no such element: Unable to locate element:

The dropdown box you are after its inside an iframe and need to switch to iframe first in order to access the element.

Induce WebDriverWait() and wait for frame_to_be_available_and_switch_to_it ()

Induce WebDriverWait() and wait for 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")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM