首页 文章

Selenium Java Firefox Windows无法正常运行

提问于
浏览
-3

我需要帮助以下组合,操作系统:使用的Windows 10浏览器:Firefox 45.0.1 Java版本:Java 8更新51(64位)Selenium:库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 ms后无法在端口7055上连接到主机127.0.0.1 . Firefox控制台输出:DEBUG为{“id”更新XPIState:“{972ce4c6-7e08-4474-a285-3208198ce6fd}”,“syncGUID”:“BbZlO30v46U7”,“location”:“app-global”,“version”:“ 45.0.1" , “类型”: “主题”, “INTERNALNAME”: “经典/ 1.0”, “器updateURL”:NULL, “updateKey”:NULL, “optionsURL”:NULL, “optionsType”:NULL, “aboutURL” :NULL, “图标”:{ “32”: “的icon.png”, “48”: “的icon.png”}, “iconURL”:NULL, “icon64URL”:NULL, “defaultLocale”:{ “名称”: “默认”,“描述”:“默认主题 . ”,“创建者”:“Mozilla”,“homepageURL”:null,“贡献者”:[“Mozilla贡献者”]},“可见”:真实,“活跃” :true,“userDisabled”:false,“appDisabled”:false,“descriptor”:“C:\ Program Files(x86)\ Mozilla Firefox \ browser \ extensions \ {972ce4c6-7e08-4474-a285-3208198ce6fd} .xpi” “installDate”:1458533973089, “updateDate”:1458533973089, “applyBackgroundUpdates”:1, “换肤功能”:真实的, “大小”:22012, “sourceURI”:空, “releaseNotesURI”:空, “softDisabled”:假” foreignInstall “:假” hasBinaryComponents “:假” strictCompatibility “:真” 的区域设置 “:[],” targetApplications “:[{” ID“: “”, “MINVERSION”: “45.0.1”, “MAXVERSION”: “45.0.1”}], “targetPlatforms”:[], “看到”:真}

1 回答

  • 3

    这是因为Firefox的最新浏览器中的新问题而发生的 .

    更新你的selenium jar . 新版本的firefox(或不同的浏览器)不支持旧 jar 的selenium .

    下载Selenium Server(以前称为Selenium RC Server)Selenium Client和WebDriver语言绑定

    用你正在使用的旧 jar 替换它们 . 同时更新您的mozilla,以便获得更新的结果

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

    要克服这个问题你还需要 setPreference 作为 xpinstall.signatures.required", false 到firefox Profile然后将它传递给驱动对象

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

    希望它能帮到你:)

相关问题