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,320 points
14,242 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,850 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.

Hey @shan were you able to achieve that through ChromeOptions?

Related Questions In Selenium

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

How to extract text from a web page using selenium and save it as a text file?

Hello Isha, you can checkout this code ...READ MORE

answered May 7, 2019 in Selenium by Anvi
• 14,010 points
7,176 views
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,510 points
1,543 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,850 points
1,486 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,850 points
1,265 views
0 votes
3 answers

How to click the search button using Selenium web driver and Python

You can try with tag. #this code will ...READ MORE

answered Apr 10, 2019 in Selenium by Matin
4,962 views
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,850 points
424 views