样例代码:
需要注意事项:
1.下载参数的配置必须在请求页面之前 driver.get(url) 前面。
private static String pathpdf = "H:\\MOBAN\\";
public static void main(String[] args) throws IOException, InterruptedException {
// TODO Auto-generated method stub
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("profile.managed_default_content_settings.images", 2);
System.setProperty("webdriver.firefox.bin", "F:\\fx\\Mozilla Firefox\\firefox.exe");
String url = "https://law.wkinfo.com.cn/document-templates/detail/VVQwMDAwMDY4MDI%3D?searchId=178b884a6c1242789fcb1b568dd4f255&index=1&q=";
// 配置响应下载参数
profile.setPreference("browser.download.dir", "H:\\MOBAN");// 下载路径
profile.setPreference("browser.download.folderList", 2);//
// 2为保存在指定路径,0代表默认路径
profile.setPreference("profile.default_content_settings.popups", 0);
// 必须添加以下两个语句才可下载成功。