Fill out form and download zipfile using Selenium in Python

I am trying to use Selenium to fill out a form and download a zipfile. After extensively googling, I have written a Python code, but I am currently unable to download the file. A browser opens, but nothing is filled out.

I am very new at Python, so I am guessing I am missing something very trivial since the website I am trying to get info from is super simple.

This is what I have tried:

from selenium import webdriver
from selenium.webdriver.common.keys import Keys

driver = webdriver.Chrome(executable_path='/home/miranda/webscrap_Python/chromedriver')
#driver.wait = WebDriverWait(driver,5)
driver.get("http://www.cis.es/cis/opencms/EN/formulario.jsp?dwld=/Microdatos/MD3288.zip")

Name = '//*[@id="Nombre"]'
LastName = '//*[@id="Apellidos"]'
University = '//*[@id="profesion"]'
email = '//*[@id="Email"]'

ob_req = '//*[@id="objeto1"]'
terms = '//*[@id="Terminos"]'

download = '//*[@id="mediomicrodatos"]/form/div[3]/input'

driver.find_element_by_xpath(Name).send_keys("Miranda")

driver.find_element_by_xpath(LastName).send_keys("MyLastName")

driver.find_element_by_xpath(University).send_keys("MySchool")

driver.find_element_by_xpath(email).send_keys("my_email@gmail.com")

driver.find_element_by_xpath(ob_req).click()
driver.find_element_by_xpath(terms).click()
driver.find_element_by_xpath(download).click()



Read more here: https://stackoverflow.com/questions/64409137/fill-out-form-and-download-zipfile-using-selenium-in-python

Content Attribution

This content was originally published by Miranda at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: