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

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)

Update 2018:

Its not valid Chrome command line switch, see the source code use hoju answer below to set the Preferences.


You can create a profile for chrome and define the download location for the tests. Here is an example:

from selenium import webdriver

options = webdriver.ChromeOptions() 

driver = webdriver.Chrome(chrome_options=options)

the exact problem I also have faced while trying to do exactly same what you want to :)

For chrome:

from selenium import webdriver
options = webdriver.ChromeOptions()
prefs = {"profile.default_content_settings.popups": 0,
                        r"C:\Users\user_dir\Desktop\\",#IMPORTANT - ENDING SLASH V IMPORTANT
             "directory_upgrade": True}
options.add_experimental_option("prefs", prefs)
browser=webdriver.Chrome(<chromdriver.exe path>, options=options)

For Firefox: follow this blog for the answer:

The blog says all about the pop up and download dir and how to do