Java Selenium WebDriver Firefox 错误 - 无法连接

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18984937/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 13:05:18  来源:igfitidea点击:

Selenium WebDriver Firefox error - Failed to connect

javaseleniumtomcat7selenium-webdriver

提问by Dev-Ria

I have done my research and found other related issues. None have helped.

我已经完成了研究并发现了其他相关问题。没有人有帮助。

so far:

迄今为止:

  • have the up to date version of selenium

  • installed older version of firefox

  • 拥有最新版本的硒

  • 安装旧版本的火狐

I have eclipse on windows 7, I created a .war and tested in eclipse under localhost:8080/JSPprojectServlets (on W7) and it works fine. selenium opens firefox, gets url, then gets source.

我在 Windows 7 上有 eclipse,我创建了一个 .war 并在 localhost:8080/JSPprojectServlets(在 W7 上)下的 eclipse 中进行了测试,它工作正常。selenium 打开 Firefox,获取 url,然后获取源。

I then put .war file into my linux (ubuntu) machine under tomcat7/webapps and try to visit it with my windows 7 machine under 192.168.1.102:8080/JSPprojectServlets but it does not work and it gives the following error:

然后我将 .war 文件放入我的 linux (ubuntu) 机器下的 tomcat7/webapps 并尝试使用我的 windows 7 机器在 192.168.1.102:8080/JSPprojectServlets 下访问它,但它不起作用,并给出以下错误:

HTTP Status 500 - Failed to connect to binary FirefoxBinary(/usr/bin/firefox) on port 7055; process output follows:

type Exception report

message Failed to connect to binary FirefoxBinary(/usr/bin/firefox) on port 7055; process output follows:

description The server encountered an internal error that prevented it from fulfilling this request.

exception

org.openqa.selenium.WebDriverException: Failed to connect to binary FirefoxBinary(/usr/bin/firefox) on port 7055; process output follows: 

(process:32704): GLib-CRITICAL **: g_slice_set_config: assertion `sys_page_size == 0' failed
Error: no display specified

(process:32711): GLib-CRITICAL **: g_slice_set_config: assertion `sys_page_size == 0' failed
Error: no display specified

Build info: version: '2.32.0', revision: '6c40c18', time: '2013-04-09 17:23:22'
System info: os.name: 'Linux', os.arch: 'amd64', os.version: '3.8.0-29-generic', java.version: '1.7.0_25'
Driver info: driver.version: FirefoxDriver
    org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.start(NewProfileExtensionConnection.java:118)
    org.openqa.selenium.firefox.FirefoxDriver.startClient(FirefoxDriver.java:244)
    org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:110)
    org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:190)
    org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:183)
    org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:179)
    org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:92)
    org.blah.blah.XmlServlet.doGet(XmlServlet.java:25)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
root cause

org.openqa.selenium.firefox.NotConnectedException: Unable to connect to host 127.0.0.1 on port 7055 after 45000 ms. Firefox console output:

(process:32704): GLib-CRITICAL **: g_slice_set_config: assertion `sys_page_size == 0' failed
Error: no display specified

(process:32711): GLib-CRITICAL **: g_slice_set_config: assertion `sys_page_size == 0' failed
Error: no display specified

    org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.start(NewProfileExtensionConnection.java:106)
    org.openqa.selenium.firefox.FirefoxDriver.startClient(FirefoxDriver.java:244)
    org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:110)
    org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:190)
    org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:183)
    org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:179)
    org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:92)
    org.blah.blah.XmlServlet.doGet(XmlServlet.java:25)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
note The full stack trace of the root cause is available in the Apache Tomcat/7.0.35 logs.

my code looks like this

我的代码看起来像这样

package org.blah.blah;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


import org.openqa.selenium.WebDriver;

import org.openqa.selenium.firefox.FirefoxDriver;
//import org.openqa.selenium.chrome.ChromeDriver;


public class XmlServlet extends HttpServlet {

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //System.out.println("Hello from GET method.");
        PrintWriter writer = response.getWriter();
        writer.println("<h3></h3>");

        WebDriver driver = new FirefoxDriver();

        driver.get("http://google.com");

        writer.println(driver.getPageSource());

    }
}

UPDATE:

更新:

When i use HtmlUnitDriver it works 192.168.1.102:8080/JSPprojectServlets

当我使用 HtmlUnitDriver 它工作 192.168.1.102:8080/JSPprojectServlets

clearly it can't open firefox for some reason. I'm in W7 64bit and have instaleld FF10 and still nothing.

显然,由于某种原因它无法打开 Firefox。我在 W7 64 位并安装了 FF10,但仍然没有。

采纳答案by Sunand Padmanabhan

Try giving the Firefox binary absolute path as a parameter in your code and when invoking from win7 provide this as in input to your JSP and then it could solve the problem. From your above stack trace it says firefox binary cannot be found in /usr/bin/firefox but you are trying to invoke the webdriver in win7 where the path is different.

尝试将 Firefox 二进制绝对路径作为代码中的参数,并在从 win7 调用时将其作为 JSP 的输入提供,然后它就可以解决问题。从上面的堆栈跟踪它说在 /usr/bin/firefox 中找不到 firefox 二进制文件,但您试图在路径不同的 win7 中调用 webdriver。

Receiving org.openqa.selenium.WebDriverException: Cannot find firefox binary in PATH running tests in Selenium IDE with Webdriver playback

接收 org.openqa.selenium.WebDriverException:在带有 Webdriver 播放的 Selenium IDE 中运行测试时,无法在 PATH 中找到 firefox 二进制文件

回答by santosh

This happens when java client fails to connect to the Selenium instance on local host. If you are running on windows make sure that "127.0.0.1 localhost" lin in hosts file is commented. Hosts file will be available in C:\Windows\System32\drivers\etc folder.

当 java 客户端无法连接到本地主机上的 Selenium 实例时,就会发生这种情况。如果您在 Windows 上运行,请确保对 hosts 文件中的“127.0.0.1 localhost” lin 进行了注释。主机文件将位于 C:\Windows\System32\drivers\etc 文件夹中。

This has fixed same issue, that i faced. This mainly happens if we are behind a proxy server.

这解决了我面临的相同问题。这主要发生在我们位于代理服务器之后。

回答by ddavison

I've experienced an issue like this with ChromeDriver, where I couldn't run tests because my chromedriver did not support my version of google chrome that i had installed on my computer.

我在 ChromeDriver 上遇到过这样的问题,我无法运行测试,因为我的 chromedriver 不支持我在计算机上安装的 google chrome 版本。

Instead of installing an old version of firefox, and having a newer FirefoxDriver, make sure both are copacetic by updating both

与其安装旧版本的 firefox 并使用更新的 FirefoxDriver,不如通过更新两者来确保两者都兼容

回答by Pushkar Srivastava

I had the same problem. Everywhere I was found root cause as version issue and really it was. This was sorted after migrating to latest version of Selenium Web Driver i.e. from 2.32 to 2.39 (As all other component like Java/Web browser etc are already up to date). All scripts are working fine now.

我有同样的问题。我到处都发现根本原因是版本问题,而且确实如此。这是在迁移到最新版本的 Selenium Web Driver 后排序的,即从 2.32 到 2.39(因为所有其他组件,如 Java/Web 浏览器等已经是最新的)。所有脚本现在都可以正常工作。

回答by user3702869

I had the same error on deploying a war and testing with Selenium on Windows 7 and apache-tomcat-6.0.37:

我在 Windows 7 和 apache-tomcat-6.0.37 上部署战争和使用 Selenium 进行测试时遇到了同样的错误:

org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.start(NewProfileExtensionConnection.java:118)

Since the tests were working before upgrading Firefox to v 27 (then 29). I tried reverting back to the earlier version of Firefox 18.0.2 (http://ftp.mozilla.org/pub/mozilla.org/firefox/releases/18.0.2/win32/en-US/) and it worked.

由于在将 Firefox 升级到 v 27(然后是 29)之前测试正在运行。我尝试恢复到早期版本的 Firefox 18.0.2 ( http://ftp.mozilla.org/pub/mozilla.org/firefox/releases/18.0.2/win32/en-US/) 并且成功了。

回答by SHAIK NAWAZ SHAREEF

I too had same problem but somehow I've resolved this issueby,

我也有同样的问题,但不知何故我已经解决了这个问题

  1. updating my JAR Files: selenium-java-2.43.0.jarto selenium-java-2.48.2.jarand selenium-server-standalone-2.43.1.jarto selenium-server-standalone-2.48.2.jar
  2. Added a new JAR file selenium-java-2.48.2-srcs.jarto lib
  1. 更新我的 JAR 文件:selenium-java-2.43.0.jarselenium-java-2.48.2.jarselenium-server-standalone-2.43.1.jarselenium-server-standalone-2.48.2.jar
  2. 添加了一个新的 JAR 文件selenium-java-2.48.2-srcs.jar到 lib

These changes made my code flawless in my case

这些更改使我的代码在我的案例中完美无缺

回答by Prade jo

update your selenium-java-*.jar file.

更新您的 selenium-java-*.jar 文件。

current version of selenium-java jar is selenium-java-2.48.2.jar

selenium-java jar 的当前版本是selenium-java-2.48.2.jar

so please use updated jar.

所以请使用更新的jar。

if you don't want to update jar files, in that case disable your firefox update

如果你不想更新 jar 文件,在这种情况下禁用你的 firefox 更新