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

我的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的步骤操作

然而,当我启动任何网站时,它不起作用并给我同样的错误。

下载Firefox 55 beta并设置

 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); 

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

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

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

在此处输入图像描述

现在使用新创建的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/"); 

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

您必须使用Marionette并将function设置为True 。

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

看起来geckodriver / Marionette还不支持它。

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

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

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

如果您想使用Selenium 3.0在Firefox上运行测试,请将Firefox驱动程序function“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(); }