4

This is a problem I've been struggling with for a few weeks now, but can't seem to find a viable solution. In a nut shell, my program goes to a website and downloads a handful of files. When it goes to download a file, FireFox always displays the popup asking where I want to save it to. In an attempt to get rid of this popup, I created a profile preference.

profile.setPreference("browser.helperApps.neverAsk.saveToDisk","application/zip,application/vnd.ms-excel");

This preference works great with the one zip file I need to download, but it's completely ignored for the other 3 Microsoft CSV files that I need. I have tried every applicable mime type I can think of and none of them work. I ran my file through an online program that is supposed to tell you what mime type the file is, and it proclaimed the file I tested was a application/vnd.ms-excel. Unfortunately though, I have never been able to get this type to work. I have tried various different ways of setting up the profile, such as:

profile.setPreference("browser.helperApps.neverAsk.saveToDisk","application/zip" + "application/vnd.ms-excel");

And even just using application/vnd.ms-excel without the zip type in front of it, and still no dice. Is there another way to set this up to where I don't have that window popup each time I try and download these files? Better yet, is there something wrong with my code that would allow the zip file to work, but not the Microsoft csv?

Jcmoney1010
  • 912
  • 7
  • 18
  • 41

1 Answers1

5

Here is a set of CSV-specific mime-types that worked for other users here on SO:

profile.setPreference('browser.helperApps.neverAsk.saveToDisk', "text/plain, application/vnd.ms-excel, text/csv, application/csv, text/comma-separated-values, application/download, application/octet-stream, binary/octet-stream, application/binary, application/x-unknown")

I'm pretty sure that the application/x-unknown is the one that would work for you since this is what Firefox itself determines as your file's mime-type (worked for me).

You may also do the following:

  • download this specific file manually with Firefox
  • when the Save File popup would be opened, check the "do this automatically for files like this from now on" checkbox and save the file
  • now, go to Help -> Troubleshooting Information
  • find the profile directory and save the path to it
  • in your Selenium code, start Firefox with the FirefoxProfile pointing to this existing profile, see more about how to do it here
Community
  • 1
  • 1
alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
  • Thanks for the quick response. Unfortunately, none of those worked. I'm about to pull my hair out! – Jcmoney1010 Jan 13 '16 at 23:36
  • @Jcmoney1010 okay, could you upload the file somewhere (with no sensitive data inside please), so I can reproduce it too? Thanks! – alecxe Jan 13 '16 at 23:37
  • yea, let me figure out where to upload to. – Jcmoney1010 Jan 13 '16 at 23:38
  • Let me know if this doesn't work. http://wikisend.com/download/699908/StackOverflow.csv – Jcmoney1010 Jan 13 '16 at 23:42
  • @Jcmoney1010 okay, for now please try two more (updated the answer as well): `binary/octet-stream` and `application/binary`. – alecxe Jan 13 '16 at 23:47
  • Unfortunately another strikeout – Jcmoney1010 Jan 13 '16 at 23:50
  • were you able to recreate the issue with the file I provided you? – Jcmoney1010 Jan 13 '16 at 23:58
  • I'm starting to think this is impossible. Nothing seems to work. I appreciate your efforts thus far. – Jcmoney1010 Jan 14 '16 at 00:23
  • 2
    @Jcmoney1010 okay, here is what you can do: open firefox, go to http://www.speedyshare.com/BeA45/d06d2a0a/StackOverflow.csv, click Slow Download. When the download file popup would be opened, choose to save the file and check the do this for this file type checkbox. Then, go to Help - Troubleshooting information, locate the path to the current firefox profile. Then, when you would start your firefox via selenium use this existing profile, see more at: http://stackoverflow.com/questions/6787095/how-to-stop-selenium-from-creating-temporary-firefox-profiles-using-web-driver. – alecxe Jan 14 '16 at 00:26
  • Will this profile be folder that is randomly named? for example `dfymf4va.default` – Jcmoney1010 Jan 14 '16 at 00:41
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/100622/discussion-between-alecxe-and-jcmoney1010). – alecxe Jan 14 '16 at 00:41
  • The answer you gave in the comment about having to put my profile as the path is what did the trick. If you want to change this to your official answer, I will give you the Big Green Check of Acceptance. Thanks for all your help! – Jcmoney1010 Jan 14 '16 at 01:37
  • @Jcmoney1010 okay, done. Glad to see we have the issue resolved. – alecxe Jan 14 '16 at 01:42
  • Thanks @alecxe for the tip on the current Firefox profile. I diffed the profile before and after saving the file via the download file popup, and found that mimeTypes.rdf changed. In there I saw a new mapping for the new (obviously incorrectly specified) mime type of the PDF file download. After adding that to the list of mime types, all is well! – Colin Jul 18 '17 at 00:38