【问题标题】:Why is Firefox not using the profile preferences via selenium?为什么 Firefox 不通过 selenium 使用配置文件首选项?
【发布时间】:2018-01-25 18:30:43
【问题描述】:

我正在尝试在 Selenium 中使用 Firefox 下载 PDF 文件,但我在下面设置的首选项似乎不起作用。每当我运行代码时,我仍然会看到"You have chosen to open:" 对话框,即使首选项声明应该自动下载 PDF 文件。

我错过了什么吗?

def setUp(self):
    downloads_folder = initialSearch.download_path(self)

    profile = webdriver.FirefoxProfile()
    profile.set_preference("browser.download.manager.showWhenStarting", False)
    profile.set_preference("browser.download.folderList", 2)
    profile.set_preference("browser.download.dir", downloads_folder)
    profile.set_preference("browser.helperApps.neverAsk.saveToDisk", "application/pdf")
    self.driver = webdriver.Firefox(profile)

【问题讨论】:

  • @DebanjanB,看看这个提要,我在这里看不到任何可以帮助我解决这个问题的东西。我看到这个问题的最后回复中引用的代码,但它几乎与我上面的代码相同,这就是为什么我对为什么我仍然得到对话框感到困惑......
  • 请问您的 Selenium 版本?
  • 我正在使用 selenium 3.8.1
  • 我在相同版本的 java 下遇到了完全相同的问题。切换到 Firefox 量子后出现此问题。但我仍然在寻找正确的偏好来禁用量子中的 pdf 查看器

标签: python selenium firefox geckodriver


【解决方案1】:

之前试试这个profile.update_preferences()

webdriver.Firefox(配置文件)

请帮助你

【讨论】:

    猜你喜欢
    • 2017-10-14
    • 1970-01-01
    • 2019-06-01
    • 2021-12-22
    • 1970-01-01
    • 2017-05-29
    • 1970-01-01
    • 2017-10-08
    相关资源
    最近更新 更多