Sai Kiran Sai Kiran - 5 months ago 481
Java Question

How to disable Chrome Plugins in Selenium WebDriver using Java

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

Answer

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");