I want to download a file and I am able to do it with the code below. When I pass options to the driver, download does not start.
from selenium import webdriver
url = "http://wwwapps.tc.gc.ca/Saf-Sec-Sur/2/CCARCS-RIACC/DDZip.aspx"
driver.get(url)
driver.find_element_by_id("btnDownload").click()
I tried to pass following options, but download does not start:
from selenium import webdriver
url = "http://wwwapps.tc.gc.ca/Saf-Sec-Sur/2/CCARCS-RIACC/DDZip.aspx"
options = webdriver.ChromeOptions()
options.add_argument("download.default_directory=H:/")
options.add_argument('headless')
options.add_argument('window-size=1920x1080')
options.add_argument("disable-gpu")
with webdriver.Chrome(chrome_options=options) as driver:
driver.get(url)
driver.find_element_by_id("btnDownload").click()
I also tried:
from selenium import webdriver
url = "http://wwwapps.tc.gc.ca/Saf-Sec-Sur/2/CCARCS-RIACC/DDZip.aspx"
with webdriver.Chrome() as driver:
prefs = {
"download.default_directory": down_dir,
"download.prompt_for_download": False,
"download.directory_upgrade": True
}
options.add_experimental_option('prefs', prefs)
driver.get(url)
driver.find_element_by_id("btnDownload").click()
I would like to download the file with hidden browser window. Also, is there a way to close it just after successful download (using driver.quit()
)?
EDIT:
I removed duplicated driver instances - error that I made during copying pieces of code.