Problem with mime type when setting preferences in FireFox with Selenium

This is a problem that I have been struggling with for several weeks but cannot find a viable solution. In the walnut shell, my program goes to the website and uploads several files. When it downloads a file, FireFox always displays a popup asking where I want to save it. 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 fine with the one zip file I need to download, but it is completely ignored for the other 3 CSV files I need. I have tried every applicable mime type that I can think of, and none of them work. I ran the file through an online program that should tell you what type of mime is the file, and declared that the file I tested was application/vnd.ms-excel. Unfortunately, although I could never get this type to work. I tried various ways of setting up a profile, for example:

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

And even just using application/vnd.ms-excelno type zipin front of him and still don’t play dice. Is there any other way to install this where I don't have this popup every time I try to download these files? Even better, is there something wrong with my code that will allow the zip file to work, but not with Microsoft csv?

+4
source share
1 answer

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 am sure that application/x-unknownthis is the one that will work for you, since that is exactly what Firefox itself defines as your mime-type file (worked for me).

You can also do the following:

  • manually download this file using Firefox
  • " " , " , ",
  • Selenium, Firefox FirefoxProfile, , ,
+5

Source: https://habr.com/ru/post/1624193/


All Articles