【问题标题】:How to handle Untrusted Certificate Selenium Webdriver in Python?如何在 Python 中处理不受信任的证书 Selenium Webdriver?
【发布时间】:2021-05-12 14:25:03
【问题描述】:

我正在使用 Selenium 访问一个站点,但我经常收到警告:潜在的安全风险。我在整个 Internet 上搜索了我的问题的解决方案,但仍然出现手动接受证书的消息。 我正在使用:

  • Firefox:85.0.1(64 位)
  • 壁虎司机
  • Python 语言

我测试了几种解决方案,例如:

from selenium import webdriver
capabilities = webdriver.DesiredCapabilities().FIREFOX
capabilities['acceptSslCerts'] = True
#capabilities['acceptInsecureCerts'] = True
driver = webdriver.Firefox(capabilities=capabilities)
driver.get('xxxxxxxxx')

还有,

from selenium import webdriver
profile = webdriver.FirefoxProfile()
profile.accept_untrusted_certs = True
driver = webdriver.Firefox(firefox_profile=profile)
driver.get('xxxxxxxxx')

我还尝试了基于在 Firefox 中创建新配置文件的解决方案。 问题是:当我使用 Selenium(Python 编程语言)启动 Firefox 时,如何自动接受网站证书?

【问题讨论】:

    标签: python python-3.x selenium selenium-webdriver firefox


    【解决方案1】:

    我解决了创建新 Firefox 配置文件并执行的问题:

    from selenium import webdriver
    from selenium.webdriver.firefox.options import Options
    options = Options()
    #Path to the Firefox Profile directory
    options.profile = r'C:\Users\x\AppData\Roaming\Mozilla\Firefox\Profiles\x.x'
    driver = webdriver.Firefox(options=options)
    driver.get('https://xxxxx')
    

    【讨论】:

      【解决方案2】:

      https://developer.mozilla.org/en-US/docs/Web/WebDriver/Capabilities/acceptInsecureCerts

      from selenium import webdriver
      capabilities = webdriver.DesiredCapabilities().FIREFOX
      capabilities['acceptInsecureCerts'] = True
      capabilities['marionette'] = True
      driver = webdriver.Firefox(desired_capabilities=capabilities)
      driver.get("https://self-signed.badssl.com/")
      

      【讨论】:

      • 感谢您的回复,但没有解决...第二个解决方案是我尝试过的解决方案,第一个解决方案引发 WebDriverException( selenium.common.exceptions.WebDriverException: 消息:浏览器出现在我们可以连接之前已经退出。如果您在 FirefoxBinary 构造函数中指定了 log_file,请检查它以获取详细信息。
      • @Raphael 使用第二个选项更新了答案
      • 它与您的解决方案相同,而不是能力使用 desired_capability=capability
      • 如果您仍然遇到该错误,请使用功能['marionette'] = True 也
      • 我希望您的解决方案可以帮助某人,但是对我来说,警告问题仍然存在......
      猜你喜欢
      • 1970-01-01
      • 2016-10-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-26
      • 2013-12-06
      • 2012-07-05
      相关资源
      最近更新 更多