-送风 2019-12-22 19:13 采纳率: 50%
浏览 711

关于selenium/standalone-chrome的启动报错Unable to determine type from: <. Last 1 characters read: <

1. java的报错信息

Exception in thread "main" org.openqa.selenium.WebDriverException: Unable to parse remote response: <!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <link rel="stylesheet" type="text/css" href="/assets/displayhelpservlet.css" media="all"/>
  <link href="/assets/favicon.ico" rel="icon" type="image/x-icon" />
  <script src="/assets/jquery-3.1.1.min.js" type="text/javascript"></script>
  <script src="/assets/displayhelpservlet.js" type="text/javascript"></script>
  <script type="text/javascript">
    var json = Object.freeze('{"consoleLink": "\u002fwd\u002fhub","type": "Standalone","class": "org.openqa.grid.web.servlet.DisplayHelpHandler$DisplayHelpServletConfig","version": "3.141.59"}');
  </script>
</head>
<body>

<div id="content">
  <div id="help-heading">
    <h1><span id="logo"></span></h1>
    <h2>Selenium <span class="se-type"></span>&nbsp;v.<span class="se-version"></span></h2>
  </div>

  <div id="content-body">
    <p>
      Whoops! The URL specified routes to this help page.
    </p>
    <p>
      For more information about Selenium <span class="se-type"></span> please see the
      <a class="se-docs">docs</a> and/or visit the <a class="se-wiki">wiki</a>.
      <span id="console-item">
        Or perhaps you are looking for the Selenium <span class="se-type"></span> <a class="se-console">console</a>.
      </span>
    </p>
    <p>
      Happy Testing!
    </p>
  </div>

  <div>
    <footer id="help-footer">
      Selenium is made possible through the efforts of our open source community, contributions from
      these <a href="https://github.com/SeleniumHQ/selenium/blob/master/AUTHORS">people</a>, and our
      <a href="http://www.seleniumhq.org/sponsors/">sponsors</a>.
   </footer>
  </div>
 </div>

</body>
</html>
    at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:115)
    at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:74)
    at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:136)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552)
    at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:213)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:131)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:144)
    at org.zhangmeng.zhi_hui_tree.ZhiHuiTreeApplication.main(ZhiHuiTreeApplication.java:21)
Caused by: org.openqa.selenium.json.JsonException: Unable to determine type from: <. Last 1 characters read: <
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
System info: host: 'zhangmengdeMacBook-Pro.local', ip: '127.0.0.1', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.15.2', java.version: '1.8.0_221'
Driver info: driver.version: RemoteWebDriver
    at org.openqa.selenium.json.JsonInput.peek(JsonInput.java:122)
    at org.openqa.selenium.json.JsonTypeCoercer.lambda$null$6(JsonTypeCoercer.java:140)
    at org.openqa.selenium.json.JsonTypeCoercer.coerce(JsonTypeCoercer.java:126)
    at org.openqa.selenium.json.Json.toType(Json.java:69)
    at org.openqa.selenium.json.Json.toType(Json.java:55)
    at org.openqa.selenium.json.Json.toType(Json.java:50)
    at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:112)
    ... 7 more

2. 运行环境

这个selenium/standalone-chrome我是拉的这个(镜像)[https://github.com/SeleniumHQ/docker-selenium]
然后就是启动镜像

docker run -d -p 4444:4444 --shm-size=2g --name selenium selenium/standalone-chrome

我的java代码是这样的

SpringApplication.run(ZhiHuiTreeApplication.class, args);
        ChromeOptions chromeOptions = new ChromeOptions();
        chromeOptions.addArguments("headless", "no-sandbox", "window-size=1200x800");
        WebDriver webDriver = new RemoteWebDriver(new URL("http://127.0.0.1:4445"), chromeOptions);
        webDriver.get("https://www.baidu.com/");
        Thread.sleep(2000);
        WebElement element = webDriver.findElement(By.xpath("//*[@id=\"tsf\"]/div[2]/div[1]/div[3]/center/input[1]"));
        System.out.println(element.getText());
        webDriver.quit();

我的maven信息

<dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>3.141.59</version>
        </dependency>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-chrome-driver</artifactId>
            <version>3.141.59</version>
        </dependency>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-server</artifactId>
            <version>3.141.59</version>
        </dependency>

3. 忙活半天了,不知道怎么解决,求懂的大神帮忙看看,感谢

  • 写回答

1条回答 默认 最新

  • lshen01 2023-03-17 10:06
    关注

    参考GPT和自己的思路:

    根据你提供的信息,可以看出是 WebDriver 无法解析 Selenium Standalone 的返回信息而引起的问题。可能的原因是Selenium Standalone 的返回信息格式发生了改变。

    你可以尝试在创建 RemoteWebDriver 实例时指定正确的 URL 以避免该问题。具体方法是在创建 RemoteWebDriver 实例时修改 URL 中的端口号为 4444,如下所示:

    ```
    WebDriver webDriver = new RemoteWebDriver(new URL("http://127.0.0.1:4444/

    评论

报告相同问题?

悬赏问题

  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题