元:-
- 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")
堆栈跟踪:-
org.openqa.selenium.WebDriverException: Reached error page: about:certerror?e=nssBadCert&u=xxxxxxxx&c=UTF-8&f=regular&d=xxxxxx%20uses%20an%20invalid%20security%20certificate.%0A%0AThe%20certificate%20is%20not%20trusted%20because%20it%20is%20self-signed.%0AThe%20certificate%20is%20not%20valid%20for%20the%20name%20xxxxxx%0A%0AError%20code%3A%20%3Ca%20id%3D%22errorCode%22%20title%3D%22SEC_ERROR_UNKNOWN_ISSUER%22%3ESEC_ERROR_UNKNOWN_ISSUER%3C/a%3E%0A Build info: version: '3.0.1', revision: '1969d75', time: '2016-10-18 09:48:19 -0700' System info: host: 'Saurabh-PC', ip: '192.168.3.8', os.name: 'Windows 10', os.arch: 'x86', os.version: '10.0', java.version: '1.8.0_71' Driver info: org.openqa.selenium.firefox.FirefoxDriver
截图:-
我也尝试过使用 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");
但问题同上。
已尝试的引用链接:-
- How to disable Firefox's untrusted connection warning using Selenium?
- https://groups.google.com/forum/?fromgroups#!topic/webdriver/frWtNrEwNPk
- Handling UntrustedSSLcertificates using WebDriver
根据 this bug通过 bug 1103196 添加了对不受信任/自签名证书的支持并将从 Firefox 52
开始可用。
但我找不到任何适用于 Firefox v51.0.1(32 位)
的解决方案。
有没有办法使用 Firefox v51.0.1(32 位)
解决这个问题?
最佳答案
如 this bug提到对不受信任/自签名证书的支持将从 Firefox 52
开始可用,我们需要等到 Firefox 52
未发布。
解决方案:-
目前,作为替代解决方案,我们需要使用现有的 Firefox 配置文件
,其中 untrusted/self-signed URL 的证书已添加到 Firefox 的异常(exception)列表
.
How to create custom Firefox profile for selenium?
- Need to follow this link to create manually custom Firefox profile
- 将不可信/自签名 URL 的证书手动添加到 Firefox 的异常(exception)列表中
使用现有配置文件启动 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");
关于java - Selenium 火狐 - WebDriverException : Reached error page: about:certerror,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42359835/