How to auto-download through Firefox browser using FirefoxProfile?

The following code block configures a Firefox Profile to Download and Save PDF files using Selenium through Java bindings:

FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("browser.download.dir", "C:\\Utility\\Downloads");
profile.setPreference("browser.download.folderList",2);
profile.setPreference("browser.helperApps.neverAsk.saveToDisk", "text/plain,application/octet-stream,application/pdf,application/x-pdf,application/vnd.pdf");
profile.setPreference("browser.download.manager.showWhenStarting", false);
profile.setPreference("browser.helperApps.neverAsk.openFile","text/plain,application/octet-stream,application/pdf,application/x-pdf,application/vnd.pdf");
profile.setPreference("browser.helperApps.alwaysAsk.force", false);
profile.setPreference("browser.download.manager.useWindow", false);
profile.setPreference("browser.download.manager.focusWhenStarting", false);
profile.setPreference("browser.helperApps.neverAsk.openFile", "");
profile.setPreference("browser.download.manager.alertOnEXEOpen", false);
profile.setPreference("browser.download.manager.showAlertOnComplete", false);
profile.setPreference("browser.download.manager.closeWhenDone", true);
profile.setPreference("pdfjs.disabled", true);
System.setProperty("webdriver.firefox.bin", "D:\\FFF\\firefox.exe");
WebDriver driver = new FirefoxDriver(profile);

Leave a Comment