- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to use chrome webdriver in Selenium to download files in Python?
We can use chrome webdriver in Selenium to download files in Python. We shall use the ChromeOptions class for this purpose. First, we shall create an object of the ChromeOptions class.
Then apply the add_experimental_option method on the object created. We shall set the download.default_directory:<location of downloaded file> parameter. Finally, this information shall be passed to the driver object.
Syntax
op = webdriver.ChromeOptions() p = {'download.default_directory':'C:\Users\ghs6kor\Downloads\Test'} op.add_experimental_option('prefs', p)
Example
from selenium import webdriver from selenium.webdriver.chrome.options import Options #object of Options class op = webdriver.ChromeOptions() #browser preferences p = {'download.default_directory':'C:\Users\ghs6kor\Downloads\Test'} #add options to browser op.add_experimental_option('prefs', p) #set chromedriver.exe path driver = webdriver.Chrome(executable_path="C:\chromedriver.exe", options=op) #maximize browser driver.maximize_window() #launch URL driver.get("https://www.seleniumhq.org/download/"); #click download link l = driver.find_element_by_link_text("32 bit Windows IE") l.click()
Output
Also, the file gets downloaded at the desired location.
- Related Articles
- How to Download & Install Selenium WebDriver?
- How to download all pdf files with selenium python?
- Running Selenium WebDriver python bindings in chrome.
- How to set default download directory in selenium Chrome Capabilities?
- How to run Selenium WebDriver test cases in Chrome?
- How can I download Microsoft WebDriver/Edge Driver to use with Selenium?
- How to mute all sounds in chrome webdriver with selenium?
- How to upload files using Selenium Webdriver?
- How do I open Chrome in selenium WebDriver?
- How to programmatically configure Chrome extension through Selenium WebDriver?
- How do you automatically download a Pdf with Selenium Webdriver in Python?
- How does Selenium Webdriver handle SSL certificate in Chrome?
- How to use a specific chrome profile in selenium?
- How to Maximize window in chrome using webDriver (Python)?
- How does selenium webdriver upload files to the browser?

Advertisements