public static void main(String[] args)
{
try
{
WebDriver driver = new FirefoxDriver(getFProfile());
driver.get("http://www.energy.umich.edu/sites/default/files/pdf-sample.pdf");
WebDriver driver1 = new FirefoxDriver(getFProfile());
driver1.get("http://samplecsvs.s3.amazonaws.com/SalesJan2009.csv");
}
catch (Exception e)
{
e.printStackTrace();
}
}
public static FirefoxProfile getFProfile()
{
FirefoxProfile firefoxProfile = new FirefoxProfile();
firefoxProfile.setPreference("browser.download.folderList", 2);
firefoxProfile.setPreference("browser.download.manager.showWhenStarting", false);
firefoxProfile.setPreference("browser.download.dir", "${user.home}\Downloads"); //C:\download
//For PDF
firefoxProfile.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/pdf");
//For CSV
firefoxProfile.setPreference("browser.helperApps.neverAsk.saveToDisk", "text/csv");
firefoxProfile.setPreference("pdfjs.disabled", true);
firefoxProfile.setPreference("plugin.scan.Acrobat", "99.0");
firefoxProfile.setPreference("plugin.scan.plid.all", false);
return firefoxProfile;
}
以上代码仅适用于。pdf文件,但显示。csv提示。如何使用单个配置文件的首选项设置自动保存两者?
使用以下修改后的单个配置文件代码:
firefoxProfile.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/pdf, text/csv");
希望这有帮助!!