允许自定义的MIME类型下载 - Selenium GeckoDriver首选项

2024-04-25 01:25:27 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试使用Firefox在Selenium测试中下载Jupyter笔记本文件(扩展名x-ipynb+json)。我使用browser.helperApps.neverAsk.saveToDisk首选项下载其他MIME类型的文件,而不使用弹出窗口:

profile = webdriver.FirefoxProfile()
profile.set_preference("browser.helperApps.neverAsk.saveToDisk",
                       "text/html, image/png," # ...others
                      )
driver = webdriver.Firefox(firefox_profile=profile)

为了获得Jupyter笔记本的相同行为,我根据this加入了application/x-ipynb+json。你知道吗

我已经手动验证了下载,这是正确的MIME类型。好像不管用。你知道吗

我使用的配置:

Python 2.7.15rc1

pytest-3.6.1

selenium 3.8.0

geckodriver 0.21.0


Tags: 文件browserjson类型selenium笔记本jupyterfirefox