Can ChromeDriver download directory be set programmatically?

5,906 views
Skip to first unread message

skd

unread,
Jan 9, 2012, 4:29:28 PM1/9/12
to seleniu...@googlegroups.com
I've set the download directory for Chrome in the browser prefs, but when my Selenium 2 test downloads a file, it is not saved there.  On Windows 7, the file is saved to <user.home>/Downloads.  On Windows XP, it's saved to <user.home>/My Documents/Downloads.  Chrome doesn't seem to have a command-line option for specifying the directory for downloads that I can use with ChromeOptions.setArguments(). 

Anyone know of a way to get the ChromeDriver to use a specific directory for downloads?  I'm using version 2.16.1 and the latest chromedriver.exe.

Krishnan Mahadevan

unread,
Jan 10, 2012, 2:00:30 AM1/10/12
to seleniu...@googlegroups.com
Perhaps try creating a specific chrome profile and then have it loaded via code at the time of instantiating ChromeDriver ?



In the above link, I read that chrome preferences are also saved along with the profiles. 
You could give it a shot and see if that helps !

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"


On Tue, Jan 10, 2012 at 2:59 AM, skd <skd...@gmail.com> wrote:
I've set the download directory for Chrome in the browser prefs, but when my Selenium 2 test downloads a file, it is not saved there.  On Windows 7, the file is saved to <user.home>/Downloads.  On Windows XP, it's saved to <user.home>/My Documents/Downloads.  Chrome doesn't seem to have a command-line option for specifying the directory for downloads that I can use with ChromeOptions.setArguments(). 

Anyone know of a way to get the ChromeDriver to use a specific directory for downloads?  I'm using version 2.16.1 and the latest chromedriver.exe.

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/rY8tjK48fewJ.
To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to selenium-user...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/selenium-users?hl=en.

skd

unread,
Jan 10, 2012, 1:41:19 PM1/10/12
to seleniu...@googlegroups.com
I can't see that creating another profile will help.  When I download files manually using the current profile, files are saved automatically to the directory specified in the prefs.  This is the relevant portion of my Preferences file:

   "download": {
      "default_directory": "C:\\datashop\\downloads",
      "directory_upgrade": true,
      "extensions_to_open": "",
      "prompt_for_download": false
   },

The ChromeDriver seems to respect the "prompt_for_download" setting, but not the "default_directory" setting.  Perhaps there is a bug in the driver?

skd

unread,
Jan 12, 2012, 12:45:06 PM1/12/12
to seleniu...@googlegroups.com
Actually, I found that .zip files are downloaded to <user.home>/Downloads on Win 7 or <user.home>/My Documents/Downloads on XP, but .txt files don't seem to be saved anywhere.

Mike Riley

unread,
Jan 12, 2012, 1:17:22 PM1/12/12
to Selenium Users
Most browsers will display a .txt file instead of downloading it.
Your would need to do a right-click on the file to choose to download
it if you were on the page manually interacting with it. I have not
tried doing downloads of a ny kind yet, so I don't have a Selenium
solution to offer you, but you would probably need to emulate a right
click and select Save As.. from the pop-up menu.

Mike

skd

unread,
Jan 12, 2012, 1:43:31 PM1/12/12
to seleniu...@googlegroups.com
In my case, the .txt file is downloaded via an 'Export' button.  There's no way to display the file in the browser. When I click the button manually, the .txt file is saved to the download directory specified in the prefs without any other interaction.

My test works as expected with Firefox but not with Chrome.

I'm having similar problems with IE, so for now I only run tests that download files on Firefox.
Reply all
Reply to author
Forward
0 new messages