javaseleniumcsvfirefoxfilesaver.js

Selenium, Firefox: How to download CSV file created by filesaver.js


I'm trying to download CSV file with Selenium on Firefox.
I saw several similar posts about this issue here, so my settings are already as following:

String downloadsPath = getFromRepository("common","//downloadsPath");
System.setProperty("webdriver.gecko.driver", "./src/main/resources/geckodriver.exe");
FirefoxProfile profile = new FirefoxProfile();
FirefoxOptions options = new FirefoxOptions();
profile.setPreference("browser.download.dir",downloadsPath);
profile.setPreference("browser.download.folderList",2);
profile.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/csv,application/excel,application/vnd.ms-excel,application/vnd.msexcel,text/anytext,text/comma-separated-values,text/csv,text/plain,text/x-csv,application/x-csv,text/x-comma-separated-values,text/tab-separated-values");
profile.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/xml,text/plain,text/xml,image/jpeg,application/octet-stream");
profile.setPreference("browser.download.manager.showWhenStarting",false);   
profile.setPreference("browser.helperApps.neverAsk.openFile","application/csv,application/excel,application/vnd.ms-excel,application/vnd.msexcel,text/anytext,text/comma-separated-values,text/csv,text/plain,text/x-csv,application/x-csv,text/x-comma-separated-values,text/tab-separated-values");  
profile.setPreference("browser.helperApps.neverAsk.openFile","application/xml,text/plain,text/xml,image/jpeg,application/octet-stream");
profile.setPreference("browser.helperApps.alwaysAsk.force", false);
options.setProfile(profile);
driver = new FirefoxDriver(options);

But all this doesn't work, I still see the pop-up dialog
I guess the problem here is because this CSV file is not actually downloaded from some server but is generated on the client side by file-saver JS
I also see in dev tools no traffic when this CSV file is downloaded.
I will appreciate any help.


Solution

  • After some researches I found that for this case data:text/csv mimeType should be added to the profile preferences.
    Now it works smooth!