3

Chrome Plugin pop up

When I am executing my Automation Code for this application the above popup is displayed. Now I would need to know how to disable PDF Viewer Plugin in Selenium WebDriver using Java.

Here's what I am using right now which is not working.

 DesiredCapabilities capabilities = DesiredCapabilities
                                .chrome();
                        ChromeOptions options = new ChromeOptions();
                        options.addArguments(new String[] { "test-type" });
                        options.addArguments(new String[] { "disable-extensions" });


String pluginToDisable = "Chrome PDF Viewer";
                        options.addArguments("plugins.plugins_disabled", pluginToDisable);


                        capabilities.setCapability("chrome.binary",
                                chromeDriver.getAbsolutePath());
                        capabilities.setCapability(ChromeOptions.CAPABILITY,
                                options);
                        options.addArguments("--lang=en-gb");
                        GlobalVars.driver = new ChromeDriver(capabilities);
S K
  • 308
  • 2
  • 6
  • 20
  • I have tried it with different combination as well. Still doesnt work. Option #1: options.addArguments("disable-plugins"); GlobalVars.driver = new ChromeDriver(options); Option #2: Map prefs = new HashMap<>(); prefs.put("plugins.plugins_disabled", "Chrome PDF Viewer"); options.setExperimentalOption("prefs", prefs); GlobalVars.driver = new ChromeDriver(options); – S K Jun 03 '16 at 16:05

5 Answers5

5

Updated for Chrome V: 57

This solution is no longer working.

Here is a valid implementation in C#:

        var options = new ChromeOptions();
        // This was a PAIN. If this ever does not work, here is how I got the preference name:
        // 1. Navigate to : chrome://settings/content
        // 2. Scroll to the bottom "PDF Documents" section
        // 3. Right-Click and inspect element on the check box titled "Open PDF files in the default PDF viewer application"
        // 4. The preference name is the pref key for the input, in this case: pref="plugins.always_open_pdf_externally"
        options.AddUserProfilePreference("plugins.always_open_pdf_externally", true);

        // The constructor must be pointed to the chrome driver .exe
        // Or you must set a PATH variable pointing to the location
        using (var driver = new ChromeDriver(options))
        {
        ..........
mheirendt
  • 51
  • 1
  • 3
3

Here is an example to disable flash and the PDF viewer with Selenium/Chrome :

ChromeOptions options = new ChromeOptions();
Map<String, Object> preferences = new Hashtable<String, Object>();
options.setExperimentalOption("prefs", preferences);

// disable flash and the PDF viewer
preferences.put("plugins.plugins_disabled", new String[] {
    "Adobe Flash Player",
    "Chrome PDF Viewer"
});

// launch the browser and navigate to the page
ChromeDriver driver = new ChromeDriver(options);
driver.get("https://www.google.co.uk");
Florent B.
  • 41,537
  • 7
  • 86
  • 101
1

It seems "plugins.plugins_disabled" or "plugins.plugins_list" doesn't work anymore. The option "plugins.always_open_pdf_externally" worked for me (mheirendt's solution). Example in Java:

ChromeOptions co = new ChromeOptions();
Map<String,Object> prefs = new HashMap<>();
prefs.put("plugins.always_open_pdf_externally", true);
co.setExperimentalOption("prefs", prefs);
WebDriver driver = new ChromeDriver(co);
timur
  • 198
  • 1
  • 2
  • 10
0

---This worked for me--

HashMap<String, Object> chromePrefs = new HashMap<String, Object>();
                    chromePrefs.put("plugins.plugins_disabled", new String[] {"Adobe Flash Player", "Chrome PDF Viewer"});
                    chromePrefs.put("profile.default_content_settings.popups", 0);
                    ChromeOptions options = new ChromeOptions();
                    options.setExperimentalOption("prefs", chromePrefs);
                    DesiredCapabilities cap = DesiredCapabilities.chrome();
                    cap.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
                    cap.setCapability(ChromeOptions.CAPABILITY, options);
                    GlobalVars.driver = new ChromeDriver(cap);
S K
  • 308
  • 2
  • 6
  • 20
0

Since Chrome's settings page is also a web app, you can programmatically crawl the settings page and disable the PDF viewer. Here is a sample python code:

browser = webdriver.Chrome("./chromedriver")    
browser.get("chrome://settings-frame/content")
pdf_section = browser.find_element_by_id("pdf-section")
pdf_disable_checkbox = pdf_section.find_element_by_tag_name("input")
if not pdf_section.is_selected():
    pdf_disable_checkbox.click()