How to control the download of files with Selenium + Python bindings in Chrome How to control the download of files with Selenium + Python bindings in Chrome google-chrome google-chrome

How to control the download of files with Selenium + Python bindings in Chrome


The path you declared for the default directory is invalid. Either escape the back slashes or provide a literal string.

options = webdriver.ChromeOptions()options.add_experimental_option("prefs", {  "download.default_directory": r"C:\Users\xxx\downloads\Test",  "download.prompt_for_download": False,  "download.directory_upgrade": True,  "safebrowsing.enabled": True})driver = webdriver.Chrome(chrome_options=options)

Here are the available preferences:

https://cs.chromium.org/chromium/src/chrome/common/pref_names.cc


It makes all the difference in the world to use the forward slash "/" when specifying the directory in which you want things to be downloaded.

I'm guessing this is because that directory will be exported to something like the Powershell, where the usual backslash "\" won't properly work.