Skip to content Skip to sidebar Skip to footer

Selenium Does Not Download With Options Passed To The Chrome Driver

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://wwwap

Solution 1:

You instantiate your webdriver twice, delete/comment out the other line:

with webdriver.Chrome(options=options) as driver:
    # driver = webdriver.Chrome(options=options)

Also not sure for Options class, I believe you should import it with:

from selenium.webdriver.chrome.optionsimportOptions

EDIT: yep, Chrome's not going to download in headless mode: SO answer.

So, the solution for you is:

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

url = "http://wwwapps.tc.gc.ca/Saf-Sec-Sur/2/CCARCS-RIACC/DDZip.aspx"defenable_download_in_headless_chrome(driver, download_dir):
    # add missing support for chrome "send_command"  to selenium webdriver
    driver.command_executor._commands["send_command"] = ("POST", '/session/$sessionId/chromium/send_command')
    params = {'cmd': 'Page.setDownloadBehavior', 'params': {'behavior': 'allow', 'downloadPath': download_dir}}
    driver.execute("send_command", params)

options = Options()
options.add_argument('--headless')
driver = webdriver.Chrome(options=options)
enable_download_in_headless_chrome(driver, "H:/")
driver.get(url)
driver.find_element_by_id("btnDownload").click()

Post a Comment for "Selenium Does Not Download With Options Passed To The Chrome Driver"