3

I'm trying to batch-download a lot of files within the BlackBoard environment (used a lot on universities/schools around the world). I am able to retrieve the links where the files are but one mayor issue:

When the file is a .pdf-file, it is shown in a new browser-tab in stead of being downloaded. For e.g. .xlsx-files downloading with a click() works just fine..

Can I change the driversettings to change this behaviour? And how?

Edit
I updated the question in reaction to Ari's answer. It's now including more info on the actual plugin. Maybe that's usable to identify the plugin which has to be disabled..

Chrome PDF Viewer (2 files)

   Name:            Chrome PDF Viewer
       Version: 
       Location:    chrome-extension://mhjfbmdgcfjbbpaeojofohoefgiehjai/
       Type:        BROWSER PLUGIN
                    Disable
       MIME types:  MIME type        Description     File extensions
                    application/pdf                  .pdf

   Name:            Chrome PDF Viewer
       Description: Portable Document Format
       Version: 
       Location:    internal-pdf-viewer
       Type:        PPAPI (out-of-process)
                    Disable
       MIME types:  MIME type        Description    File extensions
                    application/x-google-chrome-pdf Portable Document Format    
                    .pdf   
Willem van Opstal
  • 303
  • 1
  • 3
  • 13

4 Answers4

10

Chrome 57 change the setting... use this to disable Chrome PDF viewer:

//To disable PDF viewer plugins with Chrome 57
chromePrefs.put("plugins.always_open_pdf_externally", true);
  • 1
    Indeed, `'plugins.plugins_disabled': ["Chrome PDF Viewer"],` doesn't work anymore (since Chrome 57)! Thank you, you have the right solution! How did you find that? – GuiTeK Mar 28 '17 at 17:00
  • 4
    In Python, use: `chrome_options = webdriver.ChromeOptions(); chrome_options.add_experimental_option("prefs", {"download.prompt_for_download": False, "plugins.always_open_pdf_externally": True})` – Ross Smith II Apr 21 '17 at 18:25
  • 1
    In Robotframework, use: `${prefs} Create Dictionary download.default_directory ${CURDIR} plugins.always_open_pdf_externally ${TRUE}` Note the usage of `Create Dictionary` and `${TRUE}` – Sariq Shaikh May 23 '18 at 10:05
3

Ari's answer was almost working properly. I only needed to encapsulate the plugin's name into a list:

chromeOptions = webdriver.ChromeOptions()
prefs = {"plugins.plugins_disabled" : ["Chrome PDF Viewer"]} # Here should be a list
chromeOptions.add_experimental_option("prefs",prefs)
chromedriver = "path/to/chromedriver.exe"
driver = webdriver.Chrome(executable_path=chromedriver, chrome_options=chromeOptions)

The downloading now works just fine!

Willem van Opstal
  • 303
  • 1
  • 3
  • 13
1

Can you set the plugin to be disable as a preference?

chromeOptions = webdriver.ChromeOptions()
prefs = {"plugins.plugins_disabled" : "Chrome PDF Viewer"}
chromeOptions.add_experimental_option("prefs",prefs)
chromedriver = "path/to/chromedriver.exe"
driver = webdriver.Chrome(executable_path=chromedriver, chrome_options=chromeOptions)

See "setting Chrome preferences w/ Selenium Webdriver in Python" and "How to disable Chrome Plugins in Selenium WebDriver using Java".

Community
  • 1
  • 1
Ari Cooper-Davis
  • 3,374
  • 3
  • 26
  • 43
  • Thanks, but not working for me.. It doesn't disable the plugin when I check it. I updated the question, it's now including more info on the actual plugin. Maybe thats usable to identify the plugin which has to be disabled.. – Willem van Opstal Jan 26 '17 at 21:13
0
options = Options()
source_dir = r"C:\Users\........"

profile = {"download.prompt_for_download": False, "plugins.always_open_pdf_externally": True,
           "download.default_directory": source_dir}
options.add_experimental_option("prefs", profile)
driver = webdriver.Chrome(service=ChromeService(ChromeDriverManager().install()), chrome_options=options)