- 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 do you automatically download a Pdf with Selenium Webdriver in Python?
We can automatically download a pdf with the Selenium webdriver in Python. A file is downloaded in the default path set in the Chrome browser. However, we can modify the path of the downloaded file programmatically in Selenium.
This is done with the help of the Options class. We have to create an object of this class and apply the add_experimental_option. We have to pass the parameters - prefs and the path where the pdf is to be downloaded to this method. Finally, this information has to be sent to the webdriver object.
Syntax
op = Options() p = {"download.default_directory": "../pdf"} op.add_experimental_option("prefs", p)
Example
Code Implementation
from selenium import webdriver from selenium.webdriver.chrome.options import Options #Options instance op = Options() #configure path of downloaded pdf file p = {"download.default_directory": "../pdf"} op.add_experimental_option("prefs", p) #send browser option to webdriver object driver = webdriver.Chrome(executable_path='../drivers/chromedriver', options=op) #implicit wait driver.implicitly_wait(0.8) #url launch driver.get("http://demo.automationtesting.in/FileDownload.html") #browser maximize driver.maximize_window() #identify element m = driver.find_element_by_id('pdfbox') m.send_keys("infotest") t = driver.find_element_by_id('createPdf') t.click() e = driver.find_element_by_id('pdf-link-to-download') e.click() #driver close driver.close()
- Related Articles
- How to download all pdf files with selenium python?
- How do I automatically download files from a pop up dialog using selenium-python?
- How to Download & Install Selenium WebDriver?
- How to use chrome webdriver in Selenium to download files in Python?
- How can I download Microsoft WebDriver/Edge Driver to use with Selenium?
- How install Selenium Webdriver with Python?
- Download image with Selenium Python
- How do I download Selenium RC?
- Running Selenium Webdriver with a proxy in Python.
- How do I get current URL in Selenium Webdriver 2 Python?
- How to take partial screenshot with Selenium WebDriver in python?
- How do I open Chrome in selenium WebDriver?
- How to do session handling in Selenium Webdriver?
- How do you click on an element which is hidden using Selenium WebDriver?
- How do I get a parent HTML Tag with Selenium WebDriver using Java?

Advertisements