如何禁用硒中的chrome pdf查看器,并且在出现任何pdf时应以默认下载自动下载 [英] how to disable chrome pdf viewer in selenium and it should auto download in the default downloads when any pdf occurs
本文介绍了如何禁用硒中的chrome pdf查看器,并且在出现任何pdf时应以默认下载自动下载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在浏览一个网站,当我单击一个按钮时,它应该下载pdf....
i m navigating a website where i have a situation that when I m clicking on a button it should download the pdf....
我正在使用最新版本的chrome 60,selenium 3.4,chromedriver.
I am using the latest version of 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);
我也使用了上面的代码,但是不起作用.
I have also used the above code, but it doesn't work.
推荐答案
对我有用的是添加:
chromePrefs.put("plugins.always_open_pdf_externally", true);
我希望这对您有帮助
这篇关于如何禁用硒中的chrome pdf查看器,并且在出现任何pdf时应以默认下载自动下载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文