2
votes

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   
3

3 Answers

8
votes

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);
3
votes

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!

1
votes

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".