【问题标题】:Selenium + Java + Firefox + Windows is not working properlySelenium + Java + Firefox + Windows 无法正常工作
【发布时间】:2016-08-01 02:26:27
【问题描述】:

我需要以下组合的帮助, 操作系统:Windows 10 使用的浏览器:Firefox 45.0.1 Java版本:Java 8更新51(64位) 硒:图书馆 2.47.1 我们的代码很简单。

import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;
import org.testng.annotations.Test;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.AfterClass;

import java.util.List;
import java.util.concurrent.TimeUnit;

import org.testng.Assert;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
//import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

public class TestClass01 
{
    static final Logger logger1 =     LogManager.getLogger(TestClass01.class.getName());

    WebDriver driver ; 
    String baseUrl ;
    static int testCount = 0 ;
    String[] content_heading ;
    List<WebElement> temp_list ;
    WebDriverWait wait;
    boolean exists;

    @BeforeClass
    public void beforeClass() 
    {
        logger1.entry();
        logger1.info("Entering the class : " + this.getClass().getSimpleName() );

        driver = new FirefoxDriver();
        baseUrl = "http://www.google.com";

        logger1.info("Maximizing the browser window and setting up the implicit timeout for element/page loading....");
        driver.manage().window().maximize();
        //Specifies the amount of time the driver should wait when searching for an element
        driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);

        logger1.info("Fetching the Homepage for Jacuzzi");

        // launch Firefox and direct it to the Base URL
        driver.get(baseUrl+"/");


    }
}

但是,它会引发以下错误,

org.openqa.selenium.firefox.NotConnectedException:无法连接 45000 毫秒后在端口 7055 上托管 127.0.0.1。火狐控制台输出: 调试更新 XPIState 为 {"id":"{972ce4c6-7e08-4474-a285-3208198ce6fd}","syncGUID":"BbZlO30v46U7","location":"app-global","version":"45.0.1","type" :"theme","internalName":"classic/1.0","updateURL":null,"updateKey":null,"optionsURL":null,"optionsType":null,"aboutURL":null,"icons":{ "32":"icon.png","48":"icon.png"},"iconURL":null,"icon64URL":null,"defaultLocale":{"name":"Default","description": “这 默认 主题。","creator":"Mozilla","homepageURL":null,"contributors":["Mozilla 贡献者"]},"visible":true,"active":true,"userDisabled":false,"appDisabled":false,"descriptor":"C:\Program 文件 (x86)\Mozilla Firefox\browser\extensions\{972ce4c6-7e08-4474-a285-3208198ce6fd}.xpi","installDate":1458533973089,"updateDate":1458533973089,"applyBackgroundUpdates":1,"skinnable":true,"size":22012 ,"sourceURI":null,"releaseNotesURI":null,"softDisabled":false,"foreignInstall":false,"hasBinaryComponents":false,"strictCompatibility":true,"locales":[],"targetApplications":[{ "id":"{ec8030f7-c20a-464f-9b0e-13a3a9e97384}","minVersion":"45.0.1","maxVersion":"45.0.1"}],"targetPlatforms":[],"seen" :true}

【问题讨论】:

  • “大部分在线可用”——确实很有帮助。
  • 尝试降级 ff

标签: java selenium firefox


【解决方案1】:

这是因为最新的 Firefox 浏览器出现了新问题。

更新您的硒罐。新版本的firefox(或其他浏览器)不支持selenium的旧jar。

同时下载 Selenium Server(以前的 Selenium RC Server)Selenium Client 和 WebDriver 语言绑定

用您正在使用的旧罐子替换它们。也更新您的 Mozilla,以便您获得更新的结果

来源:-http://docs.seleniumhq.org/download/

要解决这个问题,您还需要将 setPreference 设为 xpinstall.signatures.required", false 到 firefox 配置文件,然后将其传递给驱动程序对象

firefoxProfile.setPreference("xpinstall.signatures.required", false);

下面的代码对我来说很好。

static WebDriver driver=null;
public static void main(String[] args) {
final FirefoxProfile firefoxProfile = new FirefoxProfile();
firefoxProfile.setPreference("xpinstall.signatures.required", false);
driver = new FirefoxDriver(firefoxProfile);
driver.get("https://www.google.de/");

希望对你有帮助:)

【讨论】:

  • 非常感谢。听从您的建议后,它工作正常。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-08-31
  • 1970-01-01
  • 2021-01-14
  • 1970-01-01
  • 2020-03-18
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多