gpt4 book ai didi

java - 如何使用 Java 在 Selenium WebDriver 中禁用 Chrome 插件

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:53:46 27 4
gpt4 key购买 nike

Chrome Plugin pop up

当我为此应用程序执行我的自动化代码时,会显示上面的弹出窗口。现在我需要知道如何使用 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))
{
..........

关于java - 如何使用 Java 在 Selenium WebDriver 中禁用 Chrome 插件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37617061/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com