Control Firefox Download Prompt Using Selenium and Python -


here code :

from selenium import webdriver 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 stop firefox show me download prompt , save automatically , have tried possible solutions didn't work. please help.

i remember providing more mime-type variants helped solve issues 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 think should not calling profile.update_preferences().


aside that, here steps see mime-type firefox detects:

  • manually download file firefox checking "automatically save file type" checkbox
  • open -> troubleshooting information
  • locate "profile folder" button, click it
  • inside profile folder locate mimetypes.rdf file
  • open file in text editor , mimetypes mentioned there - xml node attribute values start urn:mimetype
  • use mimetypes found in browser.helperapps.neverask.savetodisk comma-separated value

Comments

Popular posts from this blog

java - Suppress Jboss version details from HTTP error response -

gridview - Yii2 DataPorivider $totalSum for a column -

Sass watch command compiles .scss files before full sftp upload -