FirefoxProfile的setPreference但无法关闭“保存”对话框

时间:2014-11-06 04:46:25

标签: java firefox selenium webdriver automated-tests

我使用selenium为我的网站使用Firefox版本30进行自动化测试(称之为" A")。 我想将csv文件下载到已定义的文件夹而不显示“保存”对话框。 我已经为FirefoxProfile设置了首选项,但它没有用。

这是我的源代码:

FirefoxProfile profile = new FirefoxProfile();
      profile.setPreference("browser.download.folderList", 2);
      profile.setPreference("browser.download.dir", screenshotFolderPath); //"C:\\Users\\Administrator\\workspace\\autoTest\\screenshot\\" + screenshotFolderName + "\\" + screenshotFileName + "\\");
      profile.setPreference("browser.download.manager.alertOnEXEOpen", false);
      profile.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/msword, application/csv, application/ris, text/csv, image/png, application/pdf, text/html, text/plain, application/zip, application/x-zip, application/x-zip-compressed, application/download, application/octet-stream");
      profile.setPreference("browser.download.manager.showWhenStarting", false);
      profile.setPreference("browser.download.manager.focusWhenStarting", false);  
      profile.setPreference("browser.download.useDownloadDir", true);
      profile.setPreference("browser.helperApps.alwaysAsk.force", false);
      profile.setPreference("browser.download.manager.alertOnEXEOpen", false);
      profile.setPreference("browser.download.manager.closeWhenDone", true);
      profile.setPreference("browser.download.manager.showAlertOnComplete", false);
      profile.setPreference("browser.download.manager.useWindow", false);
      profile.setPreference("services.sync.prefs.sync.browser.download.manager.showWhenStarting", false);
      profile.setPreference("pdfjs.disabled", true);
driver = new FirefoxDriver(profile); 
driver.findElement(By.id("btn-download-log")).click();
  1. 我的源代码中有什么问题吗?

  2. 我已经尝试过这个源代码与另一个网站(称为" B")。有效。但在我的网站上(" A"),它没有。我网站的源代码是否存在任何问题(" A")?

  3. 抱歉我的英语不好。谢谢你的帮助。

1 个答案:

答案 0 :(得分:-1)

确保您的网站源代码发回一个内容标题,说明该文件为application/csv,以匹配您设置的偏好设置。

相关问题