Selenium firefox - WebDriverException:达到错误页面:about:certerror

时间:2017-02-21 06:04:47

标签: java selenium firefox selenium-firefoxdriver geckodriver

Meta: -

  • Firefox v51.0.1(32位)
  • Windows 10
  • Selenium 3.0.1
  • Geckodriver Win32 v0.13.0
  • Java v1.8.0_71

重现的步骤: -

WebDriver driver = new FirefoxDriver();
driver.get("untrusted/self-signed URL")

Stacktrace: -

  

org.openqa.selenium.WebDriverException:达到错误页面:about:certerror?e = nssBadCert& u = xxxxxxxx& c = UTF-8& f = regular& d = xxxxxx%20uses%20an%20invalid%20security%20certificate %0A%0AThe%20certificate%图20是%20not%20trusted%20because%20IT%图20是%20self签名。%0AThe%20certificate%图20是%20not%20valid%20for%第二十条%20name%20xxxxxx%0A%0AError%20code%3A %20%3CA%20id%3D%22errorCode%22%20title%3D%22SEC_ERROR_UNKNOWN_ISSUER%22%3ESEC_ERROR_UNKNOWN_ISSUER%3C /一%3E%0A   构建信息:版本:'3.0.1',修订版:'1969d75',时间:'2016-10-18 09:48:19 -0700'   系统信息:主机:'Saurabh-PC',ip:'192.168.3.8',os.name:'Windows 10',os.arch:'x86',os.version:'10 .0',java.version:'1.8 .0_71'   驱动程序信息:org.openqa.selenium.firefox.FirefoxDriver

屏幕截图: -

enter image description here

我也尝试使用FirefoxProfile: -

DesiredCapabilities dc = DesiredCapabilities.firefox();
dc.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);

FirefoxProfile profile = new FirefoxProfile();
profile.setAcceptUntrustedCertificates(true);

dc.setCapability(FirefoxDriver.PROFILE, profile);

WebDriver driver =  new FirefoxDriver(dc);
driver.get("untrusted/self-signed URL");

但问题与上述相同。

尝试过的参考链接:

根据this bug已通过bug 1103196添加了对不受信任/自签名证书的支持,并将从Firefox 52开始提供。

但我找不到Firefox v51.0.1 (32-bit)的任何解决方案。

有没有办法使用Firefox v51.0.1 (32-bit)来解决这个问题?

1 个答案:

答案 0 :(得分:2)

正如在this bug中提到的那样,从Firefox 52开始,将提供对不受信任/自签名证书的支持,我们需要等到Firefox 52未发布。

解决方案: - 目前,作为备用解决方案,我们需要使用现有的Firefox profile,其中不受信任/自签名的证书已添加到Firefox's exception list

  

如何为selenium创建自定义Firefox配置文件?

enter image description here

  • 使用现有配置文件启动Firefox: -

    System.setProperty("webdriver.gecko.driver", "path/to/geckodriver")
    
    ProfilesIni profile = new ProfilesIni();
    FirefoxProfile myprofile = profile.getProfile("created Profile Name");
    
    WebDriver driver = new FirefoxDriver(myprofile);
    driver.get("untrusted/self-signed URL");