如何在使用Java的Selenium WebDriver中禁用Chrome插件 [英] How to disable Chrome Plugins in Selenium WebDriver using Java
本文介绍了如何在使用Java的Selenium WebDriver中禁用Chrome插件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我为这个应用程序执行我的自动化代码时,显示上面的弹出窗口。现在我需要知道如何在使用Java的Selenium WebDriver中禁用PDF查看器插件。
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);
推荐答案
以下是禁用Flash和PDF查看器的示例使用Selenium / Chrome:
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");
这篇关于如何在使用Java的Selenium WebDriver中禁用Chrome插件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文