Selenium :FireFox Download popup
FirefoxProfile profile = new FirefoxProfile();
String path = "D:\\Downloads_sel";
profile.setPreference("browser.download.folderList", 2);
profile.setPreference("browser.download.dir", path);
profile.setPreference("browser.download.alertOnEXEOpen", false);
profile.setPreference("browser.helperApps.neverAsksaveToDisk", "application/x-msexcel,application/excel,application/x-excel,application/excel,application/x-excel,application/excel,application/vnd.ms-excel,application/x-excel,application/x-msexcel");
profile.setPreference("browser.download.manager.showWhenStarting", false);
profile.setPreference("browser.download.manager.focusWhenStarting", false);
profile.setPreference("browser.helperApps.alwaysAsk.force", false);
profile.setPreference("browser.download.manager.alertOnEXEOpen", false);
profile.setPreference("browser.download.manager.closeWhenDone", false);
profile.setPreference("browser.download.manager.showAlertOnComplete", false);
profile.setPreference("browser.download.manager.useWindow", false);
profile.setPreference("browser.download.manager.showWhenStarting", false);
profile.setPreference("services.sync.prefs.sync.browser.download.manager.showWhenStarting", false);
profile.setPreference("pdfjs.disabled", true);
WebDriver driver = new FirefoxDriver(profile);
Try the following prefernces depending on the type of file downloaded :
1.
profile.setPreference("browser.helperapps.neverAsk.saveToDisk" ,
"application/octet-stream;application/csv;text/csv");
2.
profile.setPreference("browser.helperapps.neverAsk.saveToDisk" ,
"application/csv");
3.
profile.setPreference("browser.helperapps.neverAsk.saveToDisk" ,
"application/excel");
4.
profile.setPreference("browser.helperapps.neverAsk.saveToDisk" ,
"application/vnd.ms-excel");
5.
profile.setPreference("browser.helperapps.neverAsk.saveToDisk" ,
"application/x-excel");
6.
profile.setPreference("browser.helperapps.neverAsk.saveToDisk" ,
"application/x-msexcel");
7.
profile.setPreference("browser.helperApps.neverAsk.saveToDisk",
"application/Zip");
8.
profile.setPreference("browser.helperApps.neverAsk.saveToDisk","image/jpg,text/csv,text/xml,application/xml,application/vnd.ms-excel,application/x-excel,application/x-msexcel,application/excel,application/pdf");
9.
profile.setPreference("browser.helperApps.neverAsk.saveToDisk","application/x-jar,application/application/vnd.android.package-archive,application/msword,application/x-rar-compressed,application/octet-stream,application/csv,text/csv");
10.profile.setPreference("browser.helperApps.neverAsk.saveToDisk","application/zip,application/x-zip,
application/x-zip-compressed, application/download,
application/octet-stream");
Simple Code :
FirefoxProfile fxProfile = new FirefoxProfile();
fxProfile.setPreference("browser.download.folderList",2);
fxProfile.setPreference("browser.download.manager.showWhenStarting",false);
fxProfile.setPreference("browser.download.dir","C:\\Downloads");
fxProfile.setPreference("browser.helperApps.neverAsk.saveToDisk","image/jpg, text/csv,text/xml,application/xml,application/vnd.ms-excel,application/x-excel,application/x-msexcel,application/excel,application/pdf");
driver = new FirefoxDriver(fxProfile);
No comments:
Post a Comment