【发布时间】:2015-07-28 09:53:16
【问题描述】:
我想使用 selenium 在 chrome 中下载 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);
我尝试了上面的代码,但它不起作用
【问题讨论】:
-
为什么不工作?哪里有问题?也许一些调试器使用?或者某些函数调用的错误状态?您尝试过什么来解决问题?
-
实际上当我点击一个按钮时,pdf应该会自动下载,在以前的浏览器版本中它可以正常工作。我的浏览器已更新,pdf 正在打开而不是下载
标签: java selenium selenium-webdriver