1

Here is my code :

from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait

profile = webdriver.FirefoxProfile()
profile.set_preference("browser.download.folderList", 2);
profile.set_preference("browser.download.manager.showWhenStarting", False)
profile.set_preference("browser.download.dir", "/home/ripundeep/Desktop/Python Challenges /")    
profile.set_preference("browser.helperApps.alwaysAsk.force", False)
profile.set_preference("browser.download.manager.alertOnEXEOpen", False)
profile.set_preference("browser.download.manager.focusWhenStarting", False)
profile.set_preference("browser.download.manager.useWindow", False)
profile.set_preference("browser.download.manager.showAlertOnComplete", False)
profile.set_preference("browser.download.manager.closeWhenDone", False)
profile.set_preference("browser.helperApps.neverAsk.openFile","text/csv")
profile.set_preference("browser.helperApps.neverAsk.saveToDisk","text/csv")
profile.update_preferences()

driver = webdriver.Firefox(firefox_profile=profile)
driver.get(url)
driver.find_element_by_css_selector("#id").send_keys("keyword")
WebDriverWait(driver, 1, poll_frequency=0.1).until(lambda drv:  len(drv.find_elements_by_css_selector("#ctl00_ContentPlaceHolder1_btnSubmit")) > 0)
driver.find_element_by_css_selector("#submitid").click()
driver.find_element_by_css_selector("#DownloadLinkId").click()

I want to stop firefox to show me download prompt and save it automatically and I have tried all possible solutions but didn't work. Please help.

2
  • Can you post some of the ...all possible solutions? Commented Jul 19, 2016 at 12:39
  • 1st solution is in code.... by changing profile of firefox using selenium. 2nd solution, I have checked "Don't ask me again" when it prompted and then re-run the code but same position occur. 3rd solution is go through the changes I can make in firefox preferences or other settings manually. But eventually nothing didn't work. As I run the code prompt ocuur. Commented Jul 19, 2016 at 12:43

2 Answers 2

4

I remember providing more mime-type variants usually helped to solve issues like this:

mime_types = [
    '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'
]
profile.set_preference("browser.helperApps.neverAsk.saveToDisk", ",".join(mime_types))

I also think you should not be calling profile.update_preferences().


Aside from that, here are the steps to see what mime-type Firefox detects:

  • manually download the file with Firefox checking the "automatically save this file type" checkbox
  • open Help -> Troubleshooting Information
  • locate the "Profile Folder" button, click it
  • inside the profile folder locate the mimeTypes.rdf file
  • open the file in a text editor and look for the mimetypes mentioned there - the XML node attribute values that start with urn:mimetype
  • use the mimetypes you found in the browser.helperApps.neverAsk.saveToDisk comma-separated value
Sign up to request clarification or add additional context in comments.

2 Comments

@user3805995 updated with instructions on how to see what mime-type firefox thinks this file is of. Hope that helps.
FYI, mimeTypes.rdf may not exist anymore. handlers.json is a possible place to look
0

You can possibly have this firefox profile, if you are using Python then you could this :

profile = FirefoxProfile()
profile.set_preference("browser.download.panel.shown", False)
profile.set_preference("browser.helperApps.neverAsk.openFile","text/csv,application/vnd.ms-excel")
profile.set_preference("browser.helperApps.neverAsk.saveToDisk", "application/msword, application/csv, application/ris, text/csv, image/png, application/pdf, text/html, text/plain, application/zip, application/x-zip, application/x-zip-compressed, application/download, application/octet-stream");
profile.set_preference("browser.download.manager.showWhenStarting", False);
profile.set_preference("browser.download.manager.alertOnEXEOpen", False);
profile.set_preference("browser.download.manager.focusWhenStarting", False);
profile.set_preference("browser.download.folderList", 2);
profile.set_preference("browser.download.useDownloadDir", True);
profile.set_preference("browser.helperApps.alwaysAsk.force", False);
profile.set_preference("browser.download.manager.alertOnEXEOpen", False);
profile.set_preference("browser.download.manager.closeWhenDone", True);
profile.set_preference("browser.download.manager.showAlertOnComplete", False);
profile.set_preference("browser.download.manager.useWindow", False);
profile.set_preference("services.sync.prefs.sync.browser.download.manager.showWhenStarting", False);
profile.set_preference("pdfjs.disabled", True);
profile.set_preference("browser.download.dir", "C:\\Users\\***\\****\\Desktop\\Automation")
driver = webdriver.Firefox(firefox_profile = profile, executable_path = "Full file path to gecko driver.exe")

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.