Website Related

Being able to save files in Selenium seems to be a common problem for users of that framework. Here is a helper method to get a Firefox driver with preferences set to allow download:

 


	public static WebDriver getDownloadCapableBrowser(File tempDir)
			throws IOException {
		boolean dirExists = tempDir.exists();

		assertTrue("Directory does not exist", dirExists);
		FirefoxProfile fp = new FirefoxProfile();
		try {
			fp.setPreference("browser.download.folderList", 2);
			fp.setPreference("browser.download.manager.showWhenStarting", false);
			fp.setPreference("browser.download.dir", tempDir.getCanonicalPath());
			fp.setPreference("browser.helperApps.alwaysAsk.force", false);
			fp.setPreference(
					"browser.helperApps.neverAsk.saveToDisk",
					"text/html,text/ofx,application/ofx,application/x-ofx,text/csv,text/x-csv,application/x-download,application/vnd.ms-excel,application/pdf");

		} catch (IOException e) {
			throw new IOException(
					"Failed to initialize Firefox with temp directory for downloads",
					e);
		}

		WebDriver driver = new FirefoxDriver(fp);

		return driver;
	}