我想使用硒下载PDF格式的铬。如何使用硒webdriver在铬下载PDF文件
System.setProperty("webdriver.chrome.driver", System.getProperty("user.dir")
+ System.getProperty("file.separator")
+ "BrowserDrivers"
+ System.getProperty("file.separator")
+ "chromedriver.exe");
String downloadFilepath = "C:\\Users\\Vinod\\Downloads";
HashMap<String, Object> chromePrefs = new HashMap<String, Object>();
chromePrefs.put("profile.default_content_settings.popups", 0);
chromePrefs.put("download.default_directory", downloadFilepath);
//Save Chrome Opions
ChromeOptions options = new ChromeOptions();
HashMap<String, Object> chromeOptionsMap = new HashMap<String, Object>();
options.setExperimentalOption("prefs", chromePrefs);
options.addArguments("--test-type");
DesiredCapabilities cap = DesiredCapabilities.chrome();
cap.setCapability(ChromeOptions.CAPABILITY, chromeOptionsMap);
cap.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
cap.setCapability(ChromeOptions.CAPABILITY, options);
driver = new ChromeDriver(cap);
driver.get(url);
我想上面的代码,但您使用Adobe Acrobat/Adobe Reader软件显示PDF文件它不工作
为什么它不工作?哪里有问题?也许有些调试器使用?或某些函数调用的错误状态?你为了解决问题而尝试过什么? –
其实当我点击一个按钮时,pdf应该自动下载,在以前的浏览器版本中它可以正常工作。我的浏览器进行了更新和PDF是开放的,而不是仅通过禁用PDF阅读器,但更新浏览器我越来越即使插件处于禁用状态问题后下载 –