无法开始新会话。可能的原因是远程服务器的无效地址或浏览器启动失败

时间:2015-06-22 12:20:47

标签: selenium

我是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

任何指针如何解决此问题。

1 个答案:

答案 0 :(得分:0)

错误消息说明了一切:

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

在这种情况下,除非你有网络故障,不允许你访问网站,它是后者 - 我检查了URL,它工作正常。

所以错误在于Safari浏览器。

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

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