如何在 selenium 中禁用 Chrome pdf 查看器,并且在出现任何 pdf 时它应该在默认下载中自动下载

0 selenium google-chrome webdriver selenium-chromedriver chrome-options

我在浏览一个网站时遇到的情况是,当我点击一个按钮时,它应该下载 pdf....

我正在使用最新版本的 chrome 60、selenium 3.4、chromedriver。

        HashMap<String, Object> chromePrefs = new HashMap<String, Object>();
        chromePrefs.put("plugins.plugins_disabled", new String[] {"Chrome PDF Viewer"});
        chromePrefs.put("profile.default_content_settings.popups", 0);
        ChromeOptions options = new ChromeOptions();
        options.setExperimentalOption("prefs", chromePrefs);
        DesiredCapabilities cap = DesiredCapabilities.chrome();
        cap.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
        cap.setCapability(ChromeOptions.CAPABILITY, options);
        WebDriver driver = new ChromeDriver(cap);
Run Code Online (Sandbox Code Playgroud)

我也使用了上面的代码,但它不起作用。

小智 6

对我有用的是添加:

chromePrefs.put("plugins.always_open_pdf_externally", true);
Run Code Online (Sandbox Code Playgroud)

我希望这有帮助


归档时间:

查看次数:

7242 次

最近记录:

5 年,5 月 前