Reputation: 175
I want to download a xlsx file from a website. And to do that I have to click on a button and I can't find it with my Python code. With my current Python code I can open the website using Selenium and open the download page and what I want is to click on "Excel: extension XLSx" button.
options=webdriver.ChromeOptions()
options.add_argument("--start-maximized")
driver=webdriver.Chrome(executable_path=path_web_crawler+"chromedriver.exe",chrome_options=options)
driver.get("https://www.ine.es/jaxiT3/Datos.htm?t=25171")
time.sleep(3)
driver.find_element_by_xpath("//input[@name='btnDescargaForm']").click()
What I tried to detect the button
elem=driver.find_element_by_xpath("//input[@value='xlsx']")
driver.execute_script("arguments[0].click();",elem)
Upvotes: 0
Views: 105
Reputation: 9969
<iframe title="Popup content - Rising content" id="thickBoxINEfrm" name="thickBoxINEfrm" frameborder="0" width="100%" height="100%" marginheight="0" marginwidth="0" tabindex="0" onload=";autoResizeThickBox(this)"></iframe>
Your element is in an iframe.
Import
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
Full Code:
driver.get("https://www.ine.es/jaxiT3/Datos.htm?t=25171")
wait = WebDriverWait(driver, 10)
wait.until(EC.element_to_be_clickable((By.XPATH,"//input[@name='btnDescargaForm']"))).click()
wait.until(EC.frame_to_be_available_and_switch_to_it((By.ID,"thickBoxINEfrm")))
elem=wait.until(EC.presence_of_element_located((By.XPATH,"//input[@value='xlsx']")))
driver.execute_script("arguments[0].click();",elem)
Upvotes: 3