Home > front end >  How to download a pdf in selenium python?
How to download a pdf in selenium python?

Time:10-08

I am using selenium webdriver to automate download PDF files, but instead I get the preview of that pdf file in chrome viewer for pdf file. How can download the file?

enter image description here

CodePudding user response:

In chrome the pdf file open internally in chrome viewer, Now to download a pdf file in selenium chrome driver python, you required to open pdf externally. To do this turn this option to true. The code is given below.

options = webdriver.ChromeOptions()
options.add_experimental_option('prefs', {
"download.default_directory": "C:/Users/XXXX/Desktop", #Change default directory for downloads
"download.prompt_for_download": False, #To auto download the file
"download.directory_upgrade": True,
"plugins.always_open_pdf_externally": True #It will not show PDF directly in chrome
})
self.driver = webdriver.Chrome(options=options)
  • Related