seleniumselenium-webdrivermime-typesfirefox-profile

Selenium WebDriver downloads .msg type on Firefox


I setup a Firefox Profile to download files on Firefox. This is my code:

String mimeTypes = "application/zip,application/octet-stream,application/vnd.ms-outlook";
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("browser.download.dir", path);
profile.setPreference("browser.download.folderList", 2);
profile.setPreference("browser.download.manager.showWhenStarting", false);
profile.setPreference("browser.helperApps.alwaysAsk.force", false);
profile.setPreference("browser.helperApps.neverAsk.saveToDisk", mimeTypes);

For zip files, it works and the file is saved automatically, without opening the Download dialog. But for .msg files it doesn't work, the Download dialog still appears and the file is not saved.

I've tried the MIME for .msg file and I found on the internet as shown in the code above, but it doesn't work.

My questions:

  1. What is the correct MIME of .msg file type?
  2. Is there a way to setPreference for neverAsk.saveToDisk to save all types without adding a long list of MIME types?

I am testing with latest FF 60 and Selenium 3.12 and geckoDriver v.0.20.

EDIT:

I don't know if this is the reason, but in my test I click to download 2 files one after one, the zip file first and then .msg file. I also tried to replaced .msg file with .jpg and .pdf and they have the same problem like with .msg file. It seems like setPreference for neverAsk.saveToDisk only affects for one MIME type


Solution

  • So, I went to check all mime types of files being downloaded. Except File1's mime type stays as it is, File2's mime type is somehow changed to application/domain-of-my-app regardless to the actual mime type of this file. After adding this new mime type application/domain-of-my-app to the list, it works as expected.