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
35,011 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,910 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?
Can you advise how to do it with Edge selenium?
As far as I know, IE does not use profiles. As such, there is no way to automatically download files to a specified location with Internet Explorer. Same with edge I guess.
this is wrong......you need to add prefrences
Hey, so is it possible in IE and edge then?

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,150 points
33,088 views
0 votes
2 answers

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,500 points
12,576 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

enable trusted connection  in internet explorer by ...READ MORE

answered Aug 31, 2020 in Selenium by Sri
• 3,190 points
8,558 views
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,910 points
6,603 views
0 votes
2 answers

How to use such xpath to find web elements

xpath are two types. 1) Absolute XPath:    /html/b ...READ MORE

answered Sep 3, 2020 in Selenium by Sri
• 3,190 points
7,506 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
15,629 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,910 points
2,325 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP