Reputation: 31
Using the following code I am downloading a file from a website , I am using Firefox 32.0.3 with Selenium jar with version- 2.43.
FirefoxProfile firefoxProfile = new FirefoxProfile();
firefoxProfile.setPreference("browser.download.folderList",2);
firefoxProfile.setPreference("browser.download.manager.showWhenStarting",false);
firefoxProfile.setPreference("browser.helperApps.alwaysAsk.force", false);
firefoxProfile.setPreference("browser.download.dir","C:\\RDM_Files");
firefoxProfile.setPreference("browser.helperApps.neverAsk.saveToDisk","application/zip;application/octet-stream;application/x-zip;application/x-zip-compressed");
firefoxProfile.setPreference("plugin.disable_full_page_plugin_for_types", "application/zip");
WebDriver driver = new FirefoxDriver(firefoxProfile);
I checked the MIME type of my file being downloaded is application/zip. Every time I try download the file a I get a window asking to either open the file or save it.
I searched Stackoverflow.com & found post related to handle a .pdf file but not a zip file. Please help
Upvotes: 3
Views: 4291
Reputation: 51
Disable popping up the System non-webpage Download/Save Dialog.
FirefoxProfile prof = new FirefoxProfile();
ffprofile.setPreference("browser.download.panel.shown", false);
ffprofile.setPreference("browser.helperApps.neverAsk.saveToDisk","application/zip");
//ffprofile.setPreference("browser.download.folderList", 1); // Default to /home/user/Downloads in Linux.
ffprofile.setPreference("browser.download.folderList", 2);
ffprofile.setPreference("browser.download.dir", "/tmp");
Upvotes: 0
Reputation: 291
I think you are looking for something like this
//common to all the cases
FirefoxProfile prof = new FirefoxProfile();
//Case:1 - Use this case to set download this code to your browser's default location
//prof.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/zip");
//Case:2 - Download file to Desktop
//prof.setPreference("browser.download.folderList", 0);
//prof.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/zip");
//Case:3 - Download to custom folder path. Replace d:\\selenium with your Download Location
prof.setPreference("browser.download.dir","D:\\selenium\\");
prof.setPreference("browser.download.folderList", 2);
prof.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/zip");
//This will work for all cases mentioned above
WebDriver driver = new FirefoxDriver(prof);
driver.get("http://docs.seleniumhq.org/download/");
driver.findElement(By.xpath("//tr[1]/td[4]/a[text()='Download']")).click();
Upvotes: 3