Selenium: automatic download

I used Selenium in the Python version. But I am stuck at the final step. I can open the browser, login, and open the download link but the file does not download automatically.

I have read the documentation, and technically I just need to set fp.set_preference("browser.helperApps.neverAsk.saveToDisk","...") with the right values, but still, it is not working.

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
import os

fp = webdriver.FirefoxProfile()

fp.set_preference("browser.download.folderList",2)
fp.set_preference("browser.download.manager.showWhenStarting",False)
fp.set_preference("browser.download.dir", os.getcwd())
fp.set_preference("browser.helperApps.neverAsk.saveToDisk", "application/EDI-X12, application/EDIFACT, application/javascript, application/octet-stream, application/ogg, application/pdf, application/xhtml+xml, application/x-shockwave-flash, application/json, application/xml, application/zip, audio/mpeg, audio/x-ms-wma, audio/vnd.rn-realaudio, audio/x-wav, image/gif, image/jpeg, image/png, image/tiff, image/vnd.microsoft.icon, image/vnd.djvu, image/svg+xml, multipart/mixed, multipart/alternative, multipart/related, text/css, text/csv, text/html, text/javascript(obsolete), text/plain, text/xml, video/mpeg, video/mp4, video/quicktime, video/x-ms-wmv, video/x-msvideo, video/x-flv, video/webm, application/vnd.oasis.opendocument.text, application/vnd.oasis.opendocument.spreadsheet, application/vnd.oasis.opendocument.presentation, application/vnd.oasis.opendocument.graphics, application/vnd.ms-excel, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-powerpoint, application/vnd.openxmlformats-officedocument.presentationml.presentation, application/msword, application/vnd.openxmlformats-officedocument.wordprocessingml.document, application/vnd.mozilla.xul+xml")

browser = webdriver.Firefox(firefox_profile=fp)
browser.get('https://www4.webcas.net/mail02/menu')


browser.find_element_by_xpath("//input[@type='text']").send_keys('login')
browser.find_element_by_xpath("//input[@type='password']").send_keys('pass' + Keys.RETURN)


time.sleep(2) # delays for 2 seconds
browser.get('https://www4.webcas.net/mail02/fm/onetime-ticket?to=enquete')
time.sleep(2) # delays for 2 seconds
browser.get('https://www4.webcas.net/form02/operator/formulator/download?enquete_id=4770')
time.sleep(2) # delays for 2 seconds

In the end, I always have the firefox popup "would you like to open or save". DL pic

Is there anything I am doing wrong ?


ANSWERS:


I found the solution.

The method is the correct one, but the parameters are not correct. I had to check the file C:\Users\User\AppData\Roaming\Mozilla\Firefox\Profiles\tofzlgfm.default\mimeTypes.rdf

Where I found the following lines

  <RDF:Description RDF:about="urn:mimetype:text/*"
                   NC:value="text/*"
                   NC:editable="true"
                   NC:fileExtensions="zip"
                   NC:description="WinZip File">
    <NC:handlerProp RDF:resource="urn:mimetype:handler:text/*"/>
  </RDF:Description>

So, I just modified my line adding text/* to the other values

I hope this will be useful to someone.



 MORE:


 ? Looking for a way to track a True Download of a file, not just the fact that they clicked on a file link
 ? How to control the download of files with Selenium Python bindings in Chrome
 ? How to position and calculate distances for elements in one-page scrolling websites?
 ? How to position and calculate distances for elements in one-page scrolling websites?
 ? How to position and calculate distances for elements in one-page scrolling websites?
 ? Div height percentage based but still scrolling
 ? How to scroll with large pages with jQuery onepage-scroll plugin?
 ? How to make a page scroll under a fixed container?
 ? Scroll when all elements on page have position absolute?
 ? HTML downloading and text extraction