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)