Firefox错误:"您的连接不安全"使用Java启动Selenium 3.0.1驱动程序

时间:2016-11-07 14:22:08

标签: java selenium firefox ssl geckodriver

我的Firefox版本是46.0.1,Selenium版本是3.0.1。 我收到了错误:

  

您的连接不安全

执行以下代码时

    @Test
public void test() {
    ProfilesIni profile = new ProfilesIni();
    FirefoxProfile ffProfile = profile.getProfile("newCretedProfile");
    ffProfile.setAcceptUntrustedCertificates(true);
    ffProfile.setAssumeUntrustedCertificateIssuer(false);
    System.setProperty("webdriver.gecko.driver", "D:\\SELENUIUM\\Drivers\\geckodriver.exe");
    FirefoxDriver driver = new FirefoxDriver(ffProfile);
    driver.get("http://www.google.com");
    driver.quit();
}

我创建了新的firefox个人资料,并按照此url

的步骤操作

然而,当我启动任何网站时,它没有工作并给我同样的错误。

5 个答案:

答案 0 :(得分:4)

下载Firefox 55测试版并设置

capabilities.setCapability("acceptInsecureCerts", true);

这是我的代码适用于Firefox 55 beta:

DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setBrowserName("firefox");
capabilities.setCapability("acceptInsecureCerts", true);
RemoteWebDriver driver = new RemoteWebDriver(Environment.remoteWebDriverURL, capabilities);

答案 1 :(得分:2)

我尝试过这种方法,但对我来说效果很好。

按照以下步骤创建新的Firefox配置文件。

  1. 关闭所有firefox窗口
  2. 在“运行”对话框中,键入:'firefox.exe -p'然后单击“确定”。
  3. 点击“创建个人资料”
  4. 为新个人资料(例如Selenium)创建一个名称
  5. 点击“选择文件夹”
  6. 选择易于查找的位置 - 例如“C:\ NewFirefoxProfile”
  7. 点击完成
  8. 现在选择新创建的配置文件后,启动Firefox。打开您获得的特定网址'安全连接问题',接受此个人资料的SSL证书。
  9. enter image description here

    现在使用新创建的firefox配置文件来运行selenium测试。根据您的要求修改以下代码。

    System.setProperty("webdriver.firefox.marionette","D:\\SELENUIUM\\Drivers\\geckodriver.exe");
    ProfilesIni profile = new ProfilesIni();    
    FirefoxProfile myprofile = profile.getProfile("C:\\NewFirefoxProfile");//location of your new firefox profile 
    WebDriver driver = new FirefoxDriver(myprofile);
    driver.get("https://cacert.org/");
    

答案 2 :(得分:2)

使用FF v53 +和Se 3.x(2017年夏季),2017年(5月?)之前的建议不再适用。

have to use Marionetteset capability to True

我花了几天时间来解决所有旧的和过时的建议,免费提供。 : - )

答案 3 :(得分:1)

geckodriver / Marionette似乎还不支持它。

您可以查看以下错误以获取更多信息: -

https://github.com/mozilla/geckodriver/issues/93

https://bugzilla.mozilla.org/show_bug.cgi?id=1103196

答案 4 :(得分:0)

如果您想使用Selenium 3.0在Firefox上运行测试,请将Firefox驱动程序功能“marionette”设置为false。

    @Test
public void test() {
    DesiredCapabilities d = new DesiredCapabilities();
    d.setCapability("marionette", false);
    WebDriver driver = new FirefoxDriver(d);
    driver.get("http://www.google.com");
    driver.quit();
}