Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selenium Webdriver in Python - files download directory change in Chrome preferences

I'm using Selenium Webdriver (in Python) to automate the downloading of thousands of files. I want to set Chrome's download folder programmatically. After reading this, I tried this:

chromepath = '/Users/thiagomarzagao/Desktop/searchcode/chromedriver' desired_caps = {'prefs': {'download': {'default_directory': '/Users/thiagomarzagao/Desktop/downloaded_files/'}}} driver = webdriver.Chrome(executable_path = chromepath, desired_capabilities = desired_caps) 

No good. Downloads still go to the default download folder ("/Users/thiagomarzagao/Downloads").

Any thoughts?

(Python 2.7.5, Selenium 2.2.0, Chromedriver 2.1.210398, Mac OS X 10.6.8)

like image 849
Parzival Avatar asked Aug 02 '13 21:08

Parzival


People also ask

How do I change ChromeDriver path?

Go to the terminal and type the command: sudo nano /etc/paths. Enter the password. At the bottom of the file, add the path of your ChromeDriver. Type Y to save.


1 Answers

The following worked for me:

chromeOptions = webdriver.ChromeOptions() prefs = {"download.default_directory" : "/some/path"} chromeOptions.add_experimental_option("prefs",prefs) chromedriver = "path/to/chromedriver.exe" driver = webdriver.Chrome(executable_path=chromedriver, options=chromeOptions) 

Source: https://sites.google.com/a/chromium.org/chromedriver/capabilities

like image 93
MervS Avatar answered Oct 06 '22 03:10

MervS