How to download a file at a specified location through python and selenium using Chrome driver

+1 vote

I was automatically downloading links using selenium with chromed river and python. How can I select the download directory through the python program so that it does not get downloaded in the default Downloads directory? 

Jul 11, 2018 in Selenium by Martin
• 4,220 points
6,855 views

1 answer to this question.

+1 vote

Create a profile for chrome and define the download location for the tests.

Below is an example:

from selenium import webdriver

options = webdriver.ChromeOptions() 

options.add_argument("download.default_directory=C:/Downloads")

driver = webdriver.Chrome(chrome_options=options)
answered Jul 11, 2018 by Samarpit
• 5,130 points
HI Sir ,

in case of multiple files needs to be  downloaded to different downloading path how can we achieve in the same browser

Hey @Shan, I'm not too confident about doing it that way. There is no use case for this scenario. 

From what I know, to change the default download location, you need to update the profile default settings by setting preferences. We use ChromeOptions in Chrome to update the preferences, in Firefox we use FirefoxProfile and for doing it in IE, we use DesiredCapabilities

The challenge however is, we cannot update the preferences during execution because it requires a restart of ChromeDriver instance. And if we restart ChromeDriver, our session will get terminated. Hence this is a no-show.

However, an alternative could be that, you set the download-to-path in the code itself. But i mist warn you, it will be extremely challenging to write the logic for the download path to change for every download. But its worth giving a short.

Related Questions In Selenium

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,050 points
261 views
0 votes
1 answer
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,130 points
629 views
0 votes
1 answer

How to use such xpath to find web elements

It's much simpler to use: #MyDiv123 > div.super or ...READ MORE

answered Jun 14, 2018 in Selenium by Samarpit
• 5,130 points
257 views
0 votes
3 answers
0 votes
1 answer

How to login a forum using Selenium with Python

You should try to directly log in ...READ MORE

answered Apr 27, 2018 in Selenium by Samarpit
• 5,130 points
246 views