Chrome 插件弹出 https://i.stack.imgur.com/jRBdG.png
当我为此应用程序执行自动化代码时,会显示上面的弹出窗口。现在我需要知道如何使用 Java 禁用 Selenium WebDriver 中的 PDF 查看器插件。
这是我现在正在使用的,但不起作用。
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);
Chrome V 更新:57
该解决方案不再有效。
下面是 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))
{
..........
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)