【问题标题】:Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure无法开始新会话。可能的原因是远程服务器地址无效或浏览器启动失败
【发布时间】:2015-09-07 21:37:17
【问题描述】:

我是 Selenium 的新手。尝试以下代码,它适用于 Firefox。 当我尝试使用 Safari 时,出现错误。

package MyTestPkg;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.safari.SafariDriver;

public class MyTestClass {
    public static void main(String[] args) {
          //WebDriver driver = new FirefoxDriver();
          WebDriver driver =new SafariDriver();
          driver.get("http://only-testing-blog.blogspot.in");
          String i = driver.getCurrentUrl();
          System.out.println(i);
          driver.close();
         }
}

OSX 10.10.3 硒 2.46 Safari 8.0.6

错误

Jun 22, 2015 5:47:12 PM org.openqa.selenium.safari.SafariDriverServer start
INFO: Server started on port 43288
Jun 22, 2015 5:47:12 PM org.openqa.selenium.safari.SafariDriverCommandExecutor start
INFO: Launching Safari
Jun 22, 2015 5:47:12 PM org.openqa.selenium.safari.SafariDriverCommandExecutor start
INFO: Waiting for SafariDriver to connect
Jun 22, 2015 5:47:14 PM org.openqa.selenium.safari.SafariDriverChannelHandler$1 operationComplete
INFO: Connection opened
Jun 22, 2015 5:47:14 PM org.openqa.selenium.safari.SafariDriverCommandExecutor start
INFO: Driver connected in 1998 ms
Jun 22, 2015 5:47:14 PM org.openqa.selenium.safari.SafariDriverCommandExecutor stop
INFO: Shutting down
Jun 22, 2015 5:47:14 PM org.openqa.selenium.safari.SafariDriverCommandExecutor stop
INFO: Closing connection
Jun 22, 2015 5:47:14 PM org.openqa.selenium.safari.SafariDriverCommandExecutor stop
INFO: Stopping Safari
Jun 22, 2015 5:47:14 PM org.openqa.selenium.safari.SafariDriverCommandExecutor stop
INFO: Stopping server
Jun 22, 2015 5:47:14 PM org.openqa.selenium.safari.SafariDriverServer stop
INFO: Stopping server
Jun 22, 2015 5:47:14 PM org.openqa.selenium.safari.SafariDriverCommandExecutor stop
INFO: Shutdown complete
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: '2.46.0', revision: '87c69e2', time: '2015-06-04 16:17:10'
System info: host: 'Lajeeshs-MacBook-Pro.local', ip: '192.168.1.224', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.10.3', java.version: '1.8.0_45'
Driver info: driver.version: SafariDriver
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:599)
    at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:242)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:128)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:141)
    at org.openqa.selenium.safari.SafariDriver.<init>(SafariDriver.java:58)
    at org.openqa.selenium.safari.SafariDriver.<init>(SafariDriver.java:42)
    at MyTestPkg.MyTestClass.main(MyTestClass.java:10)
Caused by: java.lang.ClassCastException: com.google.gson.JsonObject cannot be cast to java.lang.String
    at org.openqa.selenium.remote.JsonToBeanConverter.convert(JsonToBeanConverter.java:111)
    at org.openqa.selenium.remote.JsonToBeanConverter.convert(JsonToBeanConverter.java:42)
    at org.openqa.selenium.safari.SafariDriverCommandExecutor.execute(SafariDriverCommandExecutor.java:191)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:578)
    ... 6 more

任何指针如何解决这个问题。

【问题讨论】:

  • 您能否提供您的驱动程序详细信息以及 safari 版本?

标签: selenium


【解决方案1】:

错误信息说明了一切:

Could not start a new session.
Possible causes are invalid address of the remote server or browser start-up failure.

在这种情况下,除非您遇到网络故障导致您无法访问该网站,否则是后者 - 我检查了 URL,它工作正常。

所以错误在于 Safari 浏览器。

请注意,在不同的浏览器上运行 Selenium 测试往往需要额外的设置。

您可以尝试手动安装 Safari 驱动程序,如 here 所述,如果实际已安装。

【讨论】:

  • 嗨 Laurentiu,我已经在 Firefox 上尝试过代码,它运行良好。当我尝试 Safari 的代码时,它正在启动 Safari 浏览器,然后立即崩溃。
  • @Umasankar 检查 safari 错误日志并更新您的问题。前任。 discussions.apple.com/thread/4439369
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-08-06
  • 2020-02-25
  • 2019-04-25
  • 2022-01-04
  • 2019-07-07
  • 1970-01-01
相关资源
最近更新 更多