def set_firefox_profile(self):
    'Setup firefox with the right preferences and return a profile'
    try:
        self.download_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', 'downloads'))
        if (not os.path.exists(self.download_dir)):
            os.makedirs(self.download_dir)
    except Exception as e:
        print('Exception when trying to set directory structure')
        print(str(e))
    profile = webdriver.firefox.firefox_profile.FirefoxProfile()
    set_pref = profile.set_preference
    set_pref('browser.download.folderList', 2)
    set_pref('browser.download.dir', self.download_dir)
    set_pref('browser.download.useDownloadDir', True)
    set_pref('browser.helperApps.alwaysAsk.force', False)
    set_pref('browser.helperApps.neverAsk.openFile', 'text/csv,application/octet-stream,application/pdf')
    set_pref('browser.helperApps.neverAsk.saveToDisk', 'text/csv,application/vnd.ms-excel,application/pdf,application/csv,application/octet-stream')
    set_pref('plugin.disable_full_page_plugin_for_types', 'application/pdf')
    set_pref('pdfjs.disabled', True)
    return profile
Setup firefox with the right preferences and return a profile
def set_firefox_profile(self):
    
    try:
        self.download_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', 'downloads'))
        if (not os.path.exists(self.download_dir)):
            os.makedirs(self.download_dir)
    except Exception as e:
        print('Exception when trying to set directory structure')
        print(str(e))
    profile = webdriver.firefox.firefox_profile.FirefoxProfile()
    set_pref = profile.set_preference
    set_pref('browser.download.folderList', 2)
    set_pref('browser.download.dir', self.download_dir)
    set_pref('browser.download.useDownloadDir', True)
    set_pref('browser.helperApps.alwaysAsk.force', False)
    set_pref('browser.helperApps.neverAsk.openFile', 'text/csv,application/octet-stream,application/pdf')
    set_pref('browser.helperApps.neverAsk.saveToDisk', 'text/csv,application/vnd.ms-excel,application/pdf,application/csv,application/octet-stream')
    set_pref('plugin.disable_full_page_plugin_for_types', 'application/pdf')
    set_pref('pdfjs.disabled', True)
    return profile