0

I am using Chrome/Chromedriver version: 93.0.4577 and Selenium version: 3.141.0 on Win 10. I'm trying to get Selenium to download PDF's without opening the file prompt.

I'm working with a work site unfortunately so I'm unable to share it but I've tried the libraries: urllib, request, as well as adjusting the chrome Options (which I'd like to use):

chrome_profile = webdriver.ChromeOptions()
profile = {"plugins.plugins_list": [{"enabled": False, 
                                     "name": "Chrome PDF Viewer"}],
           "download.default_directory": "C:\\PDFDownload\\PDFs",
           "download.prompt_for_download": False,
           "download.directory_upgrade": True}

chrome_profile.add_experimental_option("prefs", profile)

driver = webdriver.Chrome(executable_path="C:\\Selenium\\chromedriver.exe",
                                       chrome_options=chrome_profile)

I've also tried switching the chrome PDF site settings from 'Open PDFs in Chrome' to 'Download PDFs' when visiting them. However, everything still prompts me to save the file manually.

I feel like the chrome Options should be the winning ticket but it doesn't seem to have worked for me. Is there something I need to change/add in order to get past the pop up prompt?

I appreciate any advice, thank you!

Mason
  • 25
  • 6
  • Recently I answered similar question. Can you look into this? https://stackoverflow.com/questions/69251242/selenium-java-how-to-download-a-pdf-and-save-with-a-different-name/69254982#69254982 – Nandan A Sep 22 '21 at 15:33
  • @NandanA Hmmm, I tried the `plugins_disabled` and `always_open_PDF_externally` but it stills gave me a pop-up. It's weird, I'll give it a new download path and it shows up in the Chrome settings, but when it comes time to actually download something, it reverts right back to the default 'Download' folder... it's just weird – Mason Sep 23 '21 at 12:02
  • Is it possible to share url? – Nandan A Sep 24 '21 at 02:12
  • Unfortunately not, I have just been using this website as a test while I'm not at work if that helps at all. Site: https://www.equibase.com/premium/eqbPDFChartPlus.cfm?RACE=1&BorP=P&TID=ALB&CTRY=USA&DT=06/17/2002&DAY=D&STYLE=EQB – Mason Oct 01 '21 at 18:35

1 Answers1

0

You can try the following:

  1. First get the 'href' or download link of the PDF you're looking for. There must be some button or link which you might want to catch.

  2. use self.driver.get(the_link_you_extracted_in_step_1) and the PDF should be automatically downloaded

Kazi
  • 381
  • 2
  • 13
  • Sorry, I've tried this as well. The PDF only has a 'src' so I've tried to use: `get_attribute('src')` in order to download it but it hasn't worked. – Mason Sep 23 '21 at 11:59