WebDriver在Firefox中禁用SEC_ERROR_UNKNOWN_ISSUER

时间:2017-08-28 08:59:54

标签: java selenium firefox selenium-webdriver

WebDriver会打开浏览器窗口,但我会收到SEC_ERROR_UNKNOWN_ISSUER。 我尝试在浏览器中添加此站点作为例外,但是当新的浏览器窗口打开时,我再次收到相同的消息,而不是网站。

FirefoxProfile profile = new FirefoxProfile();
FirefoxOptions options = new FirefoxOptions();
profile.setAcceptUntrustedCertificates(true);
profile.setAssumeUntrustedCertificateIssuer(true);
options.setLogLevel(Level.ALL);
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
capabilities.setCapability(FirefoxOptions.FIREFOX_OPTIONS, options);
WebDriver driver = new FirefoxDriver(capabilities);

1 个答案:

答案 0 :(得分:1)

您需要将setAcceptInsecureCerts功能设置为true

这个简单的代码对我有用: -

 System.setProperty("webdriver.gecko.driver", "D:\\Workspace\\StackOverlow\\src\\lib\\geckodriver.exe");
 DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
 desiredCapabilities.setAcceptInsecureCerts(true);
 WebDriver driver = new FirefoxDriver(desiredCapabilities);
 driver.get("https://self-signed.badssl.com/");

OR

     System.setProperty("webdriver.gecko.driver", "D:\\Workspace\\StackOverlow\\src\\lib\\geckodriver.exe");
     DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
     desiredCapabilities.setCapability("acceptInsecureCerts", true);
     WebDriver driver = new FirefoxDriver(desiredCapabilities);
     driver.get("https://self-signed.badssl.com/")

在第一行代码中更改您的gecko路径。更新gecko驱动和firefox

enter image description here