org.openqa.selenium.remote.UnreachableBrowserException:无法启动新会话。可能的原因是远程服务器的无效地址 [英] org.openqa.selenium.remote.UnreachableBrowserException: Could not start a new session. Possible causes are invalid address of the remote server

查看:158
本文介绍了org.openqa.selenium.remote.UnreachableBrowserException:无法启动新会话。可能的原因是远程服务器的无效地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的selenium代码无法运行。继续向我抛出以下错误:

My selenium code does not run. Keeps throwing me the following error:

Exception in thread "main" org.openqa.selenium.remote.UnreachableBrowserException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure.
Build info: version: 'unknown', revision: 'unknown', time: 'unknown'
System info: host: 'SLAP129', ip: '192.168.4.218', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_74'
Driver info: driver.version: FirefoxDriver
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:658)
    at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:250)
    at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:236)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:137)
    at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:191)
    at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:108)
    at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:104)
    at PractiseSession1.OpenBrowser(PractiseSession1.java:35)
    at PractiseSession1.main(PractiseSession1.java:16)
Caused by: java.lang.NullPointerException
    at org.openqa.selenium.remote.service.DriverService.waitUntilAvailable(DriverService.java:192)
    at org.openqa.selenium.firefox.XpiDriverService.start(XpiDriverService.java:94)
    at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:78)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:637)
    ... 8 more

FIREFOX版本:53.0.3(32位)
SELENIUM版本:selenium-java-3.4.0
我正在使用Eclipse Luna和我的机器是Windows 7(64位)。
我已阅读所有帮助查询但无法找到解决方案。这是我的Java代码:

FIREFOX VERSION: 53.0.3 (32 Bit) SELENIUM VERSION: selenium-java-3.4.0 I am using Eclipse Luna and my machine is Windows 7 (64 bit). I have read all the the help queries but could not find solution. Here is my Java code:

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
public class PractiseSession1 
{
public static void main(String[] args)

{
    // TODO Auto-generated method stub
    WebDriver driver = null;
    String URL="http://www.google.com";
    //System.out.println("Application title is =============");
    PractiseSession1 ade= new PractiseSession1();
    ade.OpenBrowser(driver);
    ade.GetPage(URL, driver);
    ade.quitbrowser(driver);
}

private void quitbrowser(WebDriver driver)
{
    driver.quit();
}
private void GetPage(String URL, WebDriver driver)
{
    driver.get(URL);
    driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
}
private void OpenBrowser(WebDriver driver)
{
    System.setProperty("webdriver.firefox.marionette", "<Geckodriver 
    path>geckodriver.exe");
    DesiredCapabilities capabilities = DesiredCapabilities.firefox();
    capabilities.setCapability("marionette", true);
    driver= new FirefoxDriver();
    driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
}
}


推荐答案

这里是你问题的答案:

你必须在代码中考虑很多因素,如下所示:

You have to consider a lot of factors in your code as follows:


  1. 您已通过 PractiseSession1 ade = new PractiseSession1(); 并使用对象 ade创建了同一类的对象调用不同的方法 OpenBrowser() GetPage() quitbrowser()。这些方法执行的功能可以通过 main()中的单行代码实现,也可以不创建任何对象。

  2. W3C标准之后使用Selenium 3.x时,要使用 geckodriver.exe ,我们需要使用 webdriver.gecko.driver 而不是 webdriver.firefox.marionette System.setProperty 行。

  3. 当你提到 System.setProperty 时,你需要提供 geckodriver.exe 的绝对路径,如下所示: / p>

  1. You have created an object of the same class through PractiseSession1 ade= new PractiseSession1(); and using the object ade to call the different methods OpenBrowser(), GetPage() and quitbrowser(). The functionality performed by the methods can be achieved through a single line of code within main() and that too without creating any object.
  2. While using Selenium 3.x following the W3C Standards, to work with geckodriver.exe we need to use webdriver.gecko.driver instead of webdriver.firefox.marionette in the System.setProperty line.
  3. While you mention System.setProperty you need to provide the absolute path of the geckodriver.exe as follows:

System.setProperty("webdriver.gecko.driver", "C:\\your_directory\\geckodriver.exe");


  • 一旦你提到 ImplicitlyWait ,它会在整个程序执行过程中保留。您可以考虑删除多个提及。

  • Once you mention ImplicitlyWait, it is retained throughout the execution of your program. You may consider removing the multiple mentions.

    driver.manage()。timeouts()。implicitlyWait(10,TimeUnit.SECONDS);

    您的整个代码只能写成6行,如下所示:

    Your entire code can be written in just 6 lines as follows:

    package demo;
    
    import java.util.concurrent.TimeUnit;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.firefox.FirefoxDriver;
    import org.openqa.selenium.remote.DesiredCapabilities;
    
    public class Q44308973_remote_unreachablebrowserexception {
    
    public static void main(String[] args) 
    {
    
    System.setProperty("webdriver.gecko.driver", "C:\\your_directory\\geckodriver.exe");
    DesiredCapabilities dc = DesiredCapabilities.firefox();
    dc.setCapability("marionette", true);
    WebDriver driver =  new FirefoxDriver(dc);
    driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
    driver.get("https://google.com");
    }
    
    }   
    


  • 详细了解 webdriver.firefox.marionette 如何演变为 webdriver.gecko.driver 你可以看这个空间

    For a detailed understanding of how webdriver.firefox.marionette evolved to be webdriver.gecko.driver you can watch this space.

    如果这回答你的问题,请告诉我。

    Let me know if this Answers your Question.

    这篇关于org.openqa.selenium.remote.UnreachableBrowserException:无法启动新会话。可能的原因是远程服务器的无效地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    相关文章
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆