当前位置: 首页 > 知识库问答 >
问题:

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

吴高洁
2023-03-14

我是硒的新手。尝试以下代码,它适用于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();
         }
}

硒Safari

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个答案

赫连越
2023-03-14

错误消息说明了一切:

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

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

因此,错误在于Safari浏览器。

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

如果确实安装了Safari驱动程序,您可以尝试按照这里的描述手动安装。

 类似资料: