How to disable Save As dialog in Selenium WebDriver tests?
Solution for Firefox (add more MIME media types if necessary):
FirefoxProfile firefoxProfile = new FirefoxProfile(); firefoxProfile.setPreference("browser.download.folderList",2); firefoxProfile.setPreference("browser.download.manager.showWhenStarting",false); firefoxProfile.setPreference("browser.download.dir", "/save/file/to/this/directory"); firefoxProfile.setPreference("browser.helperApps.neverAsk.saveToDisk","text/html, application/xhtml+xml, application/xml, application/csv, text/plain, application/vnd.ms-excel, text/csv, text/comma-separated-values, application/octet-stream"); WebDriver driver = new FirefoxDriver(firefoxProfile);
Solution for Google Chrome (this applies to all MIME media types):
Mapprefs = new Hashtable<>(); prefs.put("download.prompt_for_download", "false"); prefs.put("download.default_directory", "/save/file/to/this/directory"); DesiredCapabilities capabilities = DesiredCapabilities.chrome(); capabilities.setCapability("chrome.prefs", prefs); WebDriver driver = new ChromeDriver(capabilities);