Chase Raab Chase Raab - 10 months ago 52
Python Question

Set Firefox Preferences with Splinter

I am trying to automate a download using splinter that prompts a dialog box when initiated. To get around this, I want to set Firefox preferences to not open the box when downloading a pdf. I followed this github guide: https://github.com/seleniumhq/selenium-google-code-issue-archive/issues/7017 which appeared to address my concern. My issue now is I can't get it to work. I'm not sure where the issue is as the the script runs, but it doesn't seem to take the preferences into account.

Here is my code:

from splinter import Browser
prof = {}
prof['browser.download.manager.showWhenStarting'] = 'false'
prof['browser.helperApps.alwaysAsk.force'] = 'false'
prof['browser.download.dir'] = 'C:\Users\craab\Desktop\Notes\Confluence_Backup'
prof['browser.download.folderList'] = 2
prof['browser.helperApps.neverAsk.saveToDisk'] = 'application/pdf'
prof['browser.download.manager.useWindow'] = 'false'
prof['browser.helperApps.useWindow'] = 'false'
prof['browser.helperApps.showAlertonComplete'] = 'false'
prof['browser.helperApps.alertOnEXEOpen'] = 'false'
prof['browser.download.manager.focusWhenStarting']= 'false'
browser = Browser('firefox',profile_preferences=prof)
browser.visit('https://companywiki.com')
browser.find_by_id('login-link').click()
browser.fill('os_username', 'user')
browser.fill('os_password', 'pass')
browser.find_by_name('login').click()
browser.visit('https://pageonwiki.com')
browser.find_by_xpath('//*[@id="navigation"]/ul/li[4]').click()
browser.find_by_id('action-export-pdf-link').click()

Answer Source

I was able to achieve the same goal through saving all the preferences within the Firefox browser, then calling my Firefox profile

browser = Browser('firefox', profile=r'C:\Users\me\AppData\Roaming\Mozilla\Firefox\Profiles\0lot9hun.default')
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download