Downloading a file at a specified location through python and selenium using Chrome driver

Shubham Goyal picture Shubham Goyal · Feb 11, 2016 · Viewed 53.1k times · Source

I am trying to automatically download some links through selenium's click functionality and I am using a chrome webdriver and python as the programming language. How can I select the download directory through the python program so that it does not get downloaded in the default Downloads directory. I found a solution for firefox but there the download dialog keeps popping up every time it clicks on the link which does not happen in Chrome.

Answer

hoju picture hoju · May 4, 2017

I found the accepted solution didn't work, however this slight change did:

from selenium import webdriver

chrome_options = webdriver.ChromeOptions()
prefs = {'download.default_directory' : '/path/to/dir'}
chrome_options.add_experimental_option('prefs', prefs)
driver = webdriver.Chrome(chrome_options=chrome_options)