【问题标题】:How to disable Firefox's untrusted connection warning using Selenium?如何使用 Selenium 禁用 Firefox 的不受信任的连接警告?
【发布时间】:2013-05-28 14:09:54
【问题描述】:

试图找到一种方法来禁止 Firefox 在每次连接使用“不受信任”证书时发出警告,并使用 Selenium。我相信最有效的解决方案是设置一个浏览器首选项。

【问题讨论】:

标签: firefox ssl selenium certificate ssl-certificate


【解决方案1】:

刚刚从 Mozilla Foundation 错误链接中找到了这个,它对我有用。

caps.setCapability("acceptInsecureCerts",true)

【讨论】:

  • 我正在通过 nightwatch.js 运行 Selenium,这也适用于我。 ("acceptInsecureCerts": true)
【解决方案2】:

我找到了this comment on enabling this functionality in Selenium for Java。还有this StackOverflow question about the same issue, also for Java对于Python,这是我想要的目标语言,我通过浏览FirefoxProfile代码想出了这个:

profile = webdriver.FirefoxProfile()
profile.accept_untrusted_certs = True

据我测试,这已经产生了预期的行为。

希望这对某人有所帮助!

【讨论】:

  • 谁能告诉我如何使用 Facebook webdriver 在 PHP 中实现这一点?
  • 知道如何在节点 js 中执行此操作吗?
  • @juan carlos coto 我正在使用 python selenium 脚本。单击链接后,它会打开新窗口句柄,但上述代码未解决错误
【解决方案3】:

无需自定义配置文件来处理 WebDriver 上的“不受信任的连接

DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
driver = new FirefoxDriver(capabilities);

【讨论】:

    【解决方案4】:

    以上答案都不适合我。我正在使用: https://github.com/mozilla/geckodriver/releases/download/v0.12.0/geckodriver-v0.12.0-win64.zip

    火狐 50.1.0

    Python 3.5.2

    硒 3.0.2

    Windows 10

    我只是通过使用自定义 FF 配置文件解决了这个问题,这比我预期的要容易。使用此信息 https://support.mozilla.org/en-US/kb/profile-manager-create-and-remove-firefox-profiles#w_starting-the-profile-manager 关于如何制作自定义配置文件,我执行了以下操作: 1)制作了一个新的个人资料 2)手动去FF中的站点引发不可信证书错误 3)添加站点异常(出现错误时单击高级,然后添加异常) 4)通过重新加载站点确认异常有效(您应该不再收到错误 5)将新创建的配置文件复制到您的项目中(对我来说这是一个硒测试项目) 6) 在代码中引用新的配置文件路径

    我没有发现以下任何行为我解决了这个问题:

    firefox_capabilities = DesiredCapabilities.FIREFOX
    firefox_capabilities['handleAlerts'] = True
    firefox_capabilities['acceptSslCerts'] = True
    firefox_capabilities['acceptInsecureCerts'] = True
    profile = webdriver.FirefoxProfile()
    profile.set_preference('network.http.use-cache', False)
    profile.accept_untrusted_certs = True
    

    但是如上所述使用自定义配置文件。 这是我的代码:

    from selenium import webdriver
    from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
    
    firefox_capabilities = DesiredCapabilities.FIREFOX
    firefox_capabilities['marionette'] = True
    #In the next line I'm using a specific FireFox profile because
    # I wanted to get around the sec_error_unknown_issuer problems with the new Firefox and Marionette driver
    # I create a FireFox profile where I had already made an exception for the site I'm testing
    # see https://support.mozilla.org/en-US/kb/profile-manager-create-and-remove-firefox-profiles#w_starting-the-profile-manager
    
    ffProfilePath = 'D:\Work\PyTestFramework\FirefoxSeleniumProfile'
    profile = webdriver.FirefoxProfile(profile_directory=ffProfilePath)
    geckoPath = 'D:\Work\PyTestFramework\geckodriver.exe'
    browser = webdriver.Firefox(firefox_profile=profile, capabilities=firefox_capabilities, executable_path=geckoPath)
    browser.get('http://stackoverflow.com')
    

    【讨论】:

      【解决方案5】:

      在 C# 中从头到尾完成所有的装饰。请注意,我已将 FFv48 安装到自定义目录,因为 GeckoDriver 需要该特定版本。

          var ffOptions = new FirefoxOptions();            
          ffOptions.BrowserExecutableLocation = @"C:\Program Files (x86)\Mozilla Firefox48\firefox.exe";
          ffOptions.LogLevel = FirefoxDriverLogLevel.Default;
          ffOptions.Profile = new FirefoxProfile { AcceptUntrustedCertificates = true };            
          var service = FirefoxDriverService.CreateDefaultService(ffPath, "geckodriver.exe");            
          var Browser = new FirefoxDriver(service, ffOptions, TimeSpan.FromSeconds(120));
      

      【讨论】:

      【解决方案6】:

      就我而言,我使用的是 Marionette 驱动程序而不是 Firefox 驱动程序。它有一个公认的错误 (https://bugzilla.mozilla.org/show_bug.cgi?id=1103196)。与此同时,我正在使用 Firefox 驱动程序:

      DesiredCapabilities dc = DesiredCapabilities.firefox();
      dc.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
      
      FirefoxProfile profile = new FirefoxProfile();
      profile.setAcceptUntrustedCertificates(true);
      
      dc.setCapability(FirefoxDriver.PROFILE, profile);
      
      // this is the important line - i.e. don't use Marionette
      dc.setCapability(FirefoxDriver.MARIONETTE, false);
      
      Webdriver driver =  new FirefoxDriver(dc);
      

      【讨论】:

      • 这个错误现在被标记为已修复,您能建议如何使用已修复的 Marionette 驱动程序(我已经下载了 geckodriver.exe 0.11.1,可能还没有修复)。跨度>
      【解决方案7】:

      我添加了以下内容,然后它对我有用

      DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
      desiredCapabilities.setAcceptInsecureCerts(true);
      WebDriver driver = new FirefoxDriver(desiredCapabilities);
      

      【讨论】:

      • 这是Java,对吗?很高兴有其他语言的替代品!
      【解决方案8】:

      C#:有些东西发生了变化,因为 options 现在有自己的属性。

      var ffOptions = new FirefoxOptions();
      ffOptions.AcceptInsecureCertificates = true;
      Driver = new FirefoxDriver(ffOptions);
      

      希望这会有所帮助。

      【讨论】:

      • Options 好像没有这个能力了。
      【解决方案9】:

      对我来说,使用 PHP facebook/webdriver 我设置创建配置文件并授权认证。个人资料的名称是selenium

      接下来我初始化我的 selenium 3:

      java -jar -Dwebdriver.firefox.profile=selenium selenium-server-standalone-3.0.1.jar
      

      然后在FirefoxDriver.php 我设置const PROFILE = 'selenium';

      这对我有用。

      【讨论】:

        【解决方案10】:

        对于Firefox driverJava,添加以下行:

        WebDriver driver;
        ProfilesIni profile = new ProfilesIni();
        FirefoxProfile testprofile = profile.getProfile("default");
        testprofile.setAcceptUntrustedCertificates(true);
        testprofile.setAssumeUntrustedCertificateIssuer(true);
        driver = new FirefoxDriver(testprofile);
        

        如果您使用geckodriver,请不要忘记在配置文件初始化之前添加:

        System.setProperty("webdriver.gecko.driver","<PATH_TO_GECKODRIVER>\\geckodriver.exe");
        

        【讨论】:

          【解决方案11】:

          Java 中,您必须使用 DesiredCapabilities.setAcceptInsecureCerts()。要获得具有自定义功能和配置文件的 FirefoxDriver,请执行以下操作:

          DesiredCapabilities capabilities = new DesiredCapabilities();
          capabilities.setAcceptInsecureCerts(true);
          
          FirefoxProfile profile = new FirefoxProfile();
          profile.set*...
          
          FirefoxOptions options = new FirefoxOptions();
          options.addCapabilities(capabilities);
          options.setProfile(profile);
          
          new FirefoxDriver(options);
          

          【讨论】:

            【解决方案12】:

            在我的情况下,这成功了

            FirefoxOptions options = new FirefoxOptions();
            options.addCapabilities(new ImmutableCapabilities(ImmutableMap.of(
               CapabilityType.ACCEPT_SSL_CERTS, true,
               CapabilityType.ACCEPT_INSECURE_CERTS, true)));
            WebDriver driver = new FirefoxDriver(options);
            

            【讨论】:

              【解决方案13】:

              以上解决方案适用于 Firefox 54.0b9(64 位)。这是我的代码。

              1. 创造你的能力
              2. 根据您的要求创建 FF 配置文件
              3. 将 1. & 2. 添加到 Firefox Options 并将其传递给 FirefoxDriver

              如下图

              capabilities = new DesiredCapabilities().firefox();
              capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
              
              //Accept Untrusted connection and to download files
              FirefoxProfile profile = new FirefoxProfile();
              profile.setAcceptUntrustedCertificates(true);
              profile.setAssumeUntrustedCertificateIssuer(false);         
              profile.setPreference("dom.file.createInChild", true); 
              profile.setPreference("browser.download.folderList", 1);
              profile.setPreference("browser.helperApps.alwaysAsk.force", false);
              
              profile.setPreference("browser.download.manager.showWhenStarting"
                                         ,false);
              profile.setPreference("pdfjs.disabled", true );
              
              profile.setPreference("browser.helperApps.neverAsk.saveToDisk"
                    ,"application/pdf;image/jpg;image/jpeg;text/html;text/plain;application/zip;application/download");
              
              System.setProperty("webdriver.gecko.driver", config.getGeckoDriver());
              
              capabilities.setCapability(FirefoxDriver.PROFILE, profile);
              
              FirefoxOptions options = new FirefoxOptions();
              options.addCapabilities(capabilities);
              options.setProfile(profile);
              driver=new FirefoxDriver(options);       
              

              【讨论】:

                【解决方案14】:

                此配置在 PHP 中适用于我

                public function setUp()
                {
                    $this->setHost('localhost');
                    $this->setPort(4444);
                    $this->setBrowserUrl('https://example.loc');
                    $this->setBrowser('firefox');
                    $this->setDesiredCapabilities(["acceptInsecureCerts" => true]);
                }
                

                对于 Firefox 我运行

                java -jar selenium-server-standalone-3.8.1.jar -enablePassThrough false
                

                【讨论】:

                  【解决方案15】:

                  我在使用 Node JS 和 Selenium 时遇到了这个问题。到处搜索,但找不到任何东西。

                  终于明白了。也许这会对某人有所帮助。

                  var webdriver = require('selenium-webdriver');
                  driver = new webdriver.Builder()
                  .withCapabilities({'browserName': 'firefox', acceptSslCerts: true, acceptInsecureCerts: true})
                  .build()
                  

                  【讨论】:

                    【解决方案16】:

                    对于 PHP,请使用以下代码

                    $serverUrl = 'http://localhost:4444/wd/hub';
                    $capabilities = new DesiredCapabilities(
                        [
                            'browserName' => 'firefox',
                            'proxy' => [
                                'proxyType' => 'manual',
                                'httpProxy' => 'localhost:0000',
                                'sslProxy' => 'localhost:XXXX',
                                
                            ],
                        ]
                    );
                    
                    $capabilities->setCapability('acceptInsecureCerts',True);
                        $driver = RemoteWebDriver::create($serverUrl, $capabilities,60*1000,60*1000);
                    

                    【讨论】:

                      猜你喜欢
                      • 2012-11-03
                      • 1970-01-01
                      • 1970-01-01
                      • 2014-09-07
                      • 2013-10-10
                      • 2018-01-21
                      • 1970-01-01
                      • 1970-01-01
                      相关资源
                      最近更新 更多