Skip to content
Advertisement

How to download XLSX file through firefox using Selenium in Java?

I am trying to download an xlsx file using the following code:

FirefoxProfile profile = new FirefoxProfile();

profile.setPreference("browser.download.dir", "directory where to save data");
profile.setPreference("browser.download.folderList", 2);
profile.setPreference("browser.helperApps.alwaysAsk.force", false);
profile.setPreference("browser.download.manager.showWhenStarting", false);
profile.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/x-excel, application/x-msexcel, application/excel, application/vnd.ms-excel");

ob = new FirefoxDriver(profile);

But the test stops after displaying the download dialog box, and it is not downloading any file.

But if i try the same code for csv file by changing the mime type mentioned in the above code, then it works fine.

Please help me. Thank you.

Advertisement

Answer

Instead of the above code I added following:

firefoxProfile.setPreference("browser.download.dir",dest_path);
firefoxProfile.setPreference("browser.download.manager.showWhenStarting",false);
firefoxProfile.setPreference("browser.helperApps.neverAsk.saveToDisk","application/xls;text/csv");

And now it is working fine. The MIME type for xlsx was not working properly so instead i tried to put the MIME type for xls file and now it is working fine. The XLSX file is getting downloaded automatically.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement