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

标签 java google-chrome selenium plugins

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/

相关文章:

java - 使用 Java 添加 Tiff 图像颜色配置文件(sRGB 或 Adob​​e 1998)

javascript - Chrome 扩展程序 : dealing with multiple message listeners

css - 在 chrome 版本 57 中,固定的 css 位置在其父容器的左侧发生变化时表现奇怪

selenium - 如何 Selenium 测试使用 Google OAuth 的网站

user-interface - 如何在 Web 用户界面测试中取得成功?

java - 有没有办法将 Stream 的结果转换为 Array 并迭代 Array 元素?

java.lang.ClassNotFoundException : com. twilio.type.Endpoint tomcat 问题

java - Spring在条件类的子类中注入(inject)bean

javascript - 关于javascript函数valueOf\toString和 'curry'函数在Chrome、Firefox和node环境中的行为不同

python - 用 Python 编写的 Selenium RC 测试可以集成到 PHPUnit 中吗?