Skip to content

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("", "directory where to save data");
profile.setPreference("", 2);
profile.setPreference("browser.helperApps.alwaysAsk.force", false);
profile.setPreference("", false);
profile.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/x-excel, application/x-msexcel, application/excel, application/");

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.


Instead of the above code I added following:


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.