Problem with application/octet-stream automatic download

616 views
Skip to first unread message

MatthieuM

unread,
Oct 26, 2015, 5:12:47 AM10/26/15
to Selenium Users
Hello, 

I've been trying to run a python script using selenium python bindings which should download automatically somes files, which MIME type I have identified as application/octet-stream. I found somes explaination on how not to display a popup window on selenium FAQ and have copied it, but it does not work as expected: for my files, it still pops a confirmation dialog box.
The weird thing is that when running the same script and trying to d/l the file given in selenium FAQ example, (which has the same MIME type), it has the expected behaviour - automatically downloading to custom folder. I've also tried with other types such as application/pdf or text/plain and it worked everytime. Is there something trickier with application/octet-stream type ? 

Thanks for your inputs ! 

MatthieuM

unread,
Oct 26, 2015, 3:30:29 PM10/26/15
to Selenium Users
For anyone interested in this matter, I found what was happening : 
- The MIME type of the file I was downloading was actually not "application/octet-stream" although that is the value different websites supposed to read MIME types gave me
- I found the real MIME type in the mimeTypes.rdf file of the Firefox profile folder, by manually downloading a file of the type I wanted and selecting a "do this for all file this type" in the dialog box
- A code such as below works fine then :

from selenium import webdriver
import os

profile = webdriver.FirefoxProfile()
profile.set_preference("browser.download.folderList", 2)
profile.set_preference("browser.download.dir", os.getcwd())
profile.set_preference("browser.helperApps.neverAsk.saveToDisk", "application/gpx+tcx"); # This is the line where you should put your own MIME type. Nota : for pdf files you need a bit more
profile.set_preference("browser.helperApps.alwaysAsk.force", False);
profile.set_preference("browser.download.manager.showWhenStarting", False);

driver = webdriver.Firefox(firefox_profile=profile)

AnastasiaM

unread,
Mar 29, 2016, 11:50:45 AM3/29/16
to Selenium Users
This is the absolute guide to all the problems with the mime types in selenium. I read almost everything that was on the internet about it, everyone said it is application/octet-stream but is was not. This answer solves everything and is the fastest way to determine your mime type. Great job!
Reply all
Reply to author
Forward
0 new messages