Ishita Agrawal
Ishita Agrawal

Reputation: 11

How to download a file at a specified location through Python and Selenium using Chrome driver

I am automatically downloading some links through a website and it is getting saved by default in Download directory but I want to save those links to the desired location as per the need. I am using Python 3.

I am using this code but it is not working.

options = webdriver.ChromeOptions()
options.add_argument("download.default_directory=C://Users//ASUS//Downloads")
driver = webdriver.Chrome(r"C:\Users\ASUS\Downloads\chromedriver.exe",chrome_options=options)
driver.implicitly_wait(30)

Any type of help will be appreciated.

Thank you..

Upvotes: 0

Views: 596

Answers (1)

undetected Selenium
undetected Selenium

Reputation: 193088

As per your code trial you have set the download.default_directory through an instance of ChromeOptions while initializing the WebDriver and WebBrowser instance which remains unchanged throughout the lifespan of the WebDriver and WebBrowser instance.

While the WebDriver and WebBrowser instance is active even if you are able to extract any of the capabilities or other session attributes from the current Browsing Session still you won't be able to change any of those attributes of the currently active WebDriver instance e.g download.default_directory. If you want to change any of the capabilities or other session attributes you have re-configure the WebDriver instance again.

Upvotes: 0

Related Questions