线程“main”中的异常org.openqa.selenium.remote.UnreachableBrowserException:无法启动新会话

时间:2016-07-08 06:18:35

标签: selenium-webdriver

我刚开始学习Selenium WebDriver。你能帮我解决下面的问题。 我只是想打开网站(我能够成功打开浏览器,但导航失败了)

import java.util.concurrent.TimeUnit;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;

public class webdriverdemo {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        WebDriver driver = new FirefoxDriver();

        //Puts an Implicit wait, Will wait for 10 seconds before throwing exception
        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

        //Launch website
        driver.navigate().to("http://www.calculator.net/");

        //Maximize the browser
        driver.manage().window().maximize();
    }
}

我发现以下错误:

  

线程“main”中的异常   org.openqa.selenium.remote.UnreachableBrowserException:不能   开始一个新的会议。可能的原因是遥控器的无效地址   服务器或浏览器启动失败。       构建信息:版本:'2.53.0',修订版:'35ae25b',时间:'2016-03-15 17:00:58'       系统信息:主机:'WIN-EHSO6G1D9KD',ip:'192.168.13.2',os.name:'Windows Server 2012',os.arch:'amd64',os.version:'6.2',   java.version:'1.8.0_91'       驱动程序信息:driver.version:FirefoxDriver         在org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:665)         在org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:249)         在org.openqa.selenium.remote.RemoteWebDriver。(RemoteWebDriver.java:131)         在org.openqa.selenium.firefox.FirefoxDriver。(FirefoxDriver.java:218)         在org.openqa.selenium.firefox.FirefoxDriver。(FirefoxDriver.java:211)         在org.openqa.selenium.firefox.FirefoxDriver。(FirefoxDriver.java:207)         在org.openqa.selenium.firefox.FirefoxDriver。(FirefoxDriver.java:120)         在webdriverdemo.main(webdriverdemo.java:13)       引起:java.net.SocketException:连接重置         在java.net.SocketInputStream.read(未知来源)         在java.net.SocketInputStream.read(未知来源)         at org.apache.http.impl.io.SessionInputBufferImpl.streamRead(SessionInputBufferImpl.java:139)         at org.apache.http.impl.io.SessionInputBufferImpl.fillBuffer(SessionInputBufferImpl.java:155)         at org.apache.http.impl.io.SessionInputBufferImpl.readLine(SessionInputBufferImpl.java:284)         at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:140)         at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:57)         在org.apache.http.impl.io.AbstractMessageParser.parse(AbstractMessageParser.java:261)         at org.apache.http.impl.DefaultBHttpClientConnection.receiveResponseHeader(DefaultBHttpClientConnection.java:165)         在org.apache.http.impl.conn.CPoolProxy.receiveResponseHeader(CPoolProxy.java:167)         at org.apache.http.protocol.HttpRequestExecutor.doReceiveResponse(HttpRequestExecutor.java:272)         在org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:124)         在org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:271)         在org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:184)         在org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:88)         在org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:110)         在org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:184)         在org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:71)         在org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:55)         在org.openqa.selenium.remote.internal.ApacheHttpClient.fallBackExecute(ApacheHttpClient.java:144)         在org.openqa.selenium.remote.internal.ApacheHttpClient.execute(ApacheHttpClient.java:90)         在org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:142)         在org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.execute(NewProfileExtensionConnection.java:160)         在org.openqa.selenium.firefox.FirefoxDriver $ LazyCommandExecutor.execute(FirefoxDriver.java:380)         在org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:644)

... 7更多

Firefox版本47.0.6 平台Win2k12 r2

1 个答案:

答案 0 :(得分:0)

似乎与Firefox创建会话存在一些问题。 尝试以下代码并使用Chrome浏览器进行测试。

您需要从https://sites.google.com/a/chromium.org/chromedriver/downloads

下载可执行驱动程序
public static void main(String[] args){
    System.setProperty("webdriver.chrome.driver","/path/to/chromedriver");
    WebDriver driver = new ChromeDriver();
    driver = new ChromeDriver();
    //Puts an Implicit wait, Will wait for 10 seconds before throwing exception
    driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

    //Launch website
    driver.get("http://www.calculator.net/");

    //Maximize the browser
    driver.manage().window().maximize();
}