设置限制Firefox配置文件的下载文件大小?

时间:2018-01-23 12:51:40

标签: python selenium firefox

我正在设置我的firefox配置文件:

        firefox_capabilities = DesiredCapabilities.FIREFOX

        ff_profile = webdriver.FirefoxProfile()
        ff_profile.set_preference('browser.download.folderList', 2)
        ff_profile.set_preference('browser.download.manager.showWhenStarting', False)
        ff_profile.set_preference('browser.download.dir', self.download_dir)
        ff_profile.set_preference('browser.helperApps.neverAsk.saveToDisk', 'application/zip')
        ff_profile.set_preference('app.update.auto', False)
        ff_profile.set_preference('app.update.enabled', False)
        ff_profile.set_preference('webgl.disabled', True)
        ff_profile.set_preference('webdriver.log.file', getenv('PWD') + '/firefox_webdriver.log')
        ff_profile.set_preference('webdriver.firefox.logfile', getenv('PWD') + '/firefox_browser.log')

        driver = webdriver.Firefox(firefox_profile=ff_profile,
                                   capabilities=firefox_capabilities)

当我使用驱动程序下载某个特定大小以下的文件时,一切都很好。如果超过一定的大小,测试将无法找到下载的文件,因为Firefox提供了一个包含以下内容的对话框:

You have chosen to open: [the file name] 
which is: Binary File 
from: [the source location].  
Would you like to save this file?

如果我使用调试器逐步完成测试,并手动接受此对话框,一切都很顺利。这个特定文件的不同之处在于它是6MB。其他成功下载的文件要小得多,不到1MB。这表明,尽管有我的个人资料设置,Firefox确定的某个文件大小太大,无法在未经批准的情况下下载。

我搜索了Firefox的about:config中的设置,但我没有发现任何似乎可以解决这个问题。

您是否了解我可以在个人资料中设置的其他偏好设置,以便我可以增加此文件大小限制?还有其他方法可以解决这个问题吗?

1 个答案:

答案 0 :(得分:0)

好的,有人向我指出,区别不是大小,而是文件类型。我需要做的就是在我的偏好中容纳额外的文件类型:

   ff_profile.set_preference('browser.helperApps.neverAsk.saveToDisk',
                             'application/zip, attachment/csv, application/octet-stream')
相关问题