Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/381.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 尝试双方言会话,假设Postel';s定律适用于远端&;使用ChromeDriver和Selenium返回到原始OSS JSON_Java_Selenium_Google Chrome_Selenium Webdriver_Selenium Chromedriver - Fatal编程技术网

Java 尝试双方言会话,假设Postel';s定律适用于远端&;使用ChromeDriver和Selenium返回到原始OSS JSON

Java 尝试双方言会话,假设Postel';s定律适用于远端&;使用ChromeDriver和Selenium返回到原始OSS JSON,java,selenium,google-chrome,selenium-webdriver,selenium-chromedriver,Java,Selenium,Google Chrome,Selenium Webdriver,Selenium Chromedriver,下面是我用来初始化chrome webdriver的代码片段: System.out.println("Initializing Chrome"); ChromeOptions options = new ChromeOptions(); //options.setBinary("C:/Program Files (x86)/Google/Chrome/Application"); options.addArguments("start-maximized"); options.setExper

下面是我用来初始化chrome webdriver的代码片段:

System.out.println("Initializing Chrome");
ChromeOptions options = new ChromeOptions();
//options.setBinary("C:/Program Files (x86)/Google/Chrome/Application");
options.addArguments("start-maximized");
options.setExperimentalOption("excludeSwitches",new String[]{"enable-automation"});
options.addArguments("--disable-extensions");
options.addArguments("--disable-infobars");
options.addArguments("--allow-running-insecure-content");
WDriver = new ChromeDriver(options);
//WDriver = new ChromeDriver();
WDriver.manage().timeouts().implicitlyWait(60,TimeUnit.SECONDS);
System.out.println("Chrome Initialization Complete");
但它似乎打开了两个chrome实例,这显示在控制台上:

Initializing Chrome
Starting ChromeDriver 78.0.3904.70 (edb9c9f3de0247fd912a77b7f6cae7447f6d3ad5-refs/branch- 
heads/3904@{#800}) on port 12262
Only local connections are allowed.
Please protect ports used by ChromeDriver and related test frameworks to prevent access by malicious 
code.
Nov 04, 2019 3:29:38 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Attempting bi-dialect session, assuming Postel's Law holds true on the remote end
log4j:WARN No appenders could be found for logger 
(org.apache.http.client.protocol.RequestAddCookies).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
[1572910181.451][WARNING]: Timed out connecting to Chrome, retrying...
Nov 04, 2019 3:29:43 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Falling back to original OSS JSON Wire Protocol.
[1572910186.002][WARNING]: Timed out connecting to Chrome, retrying...
Nov 04, 2019 3:29:48 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: OSS
Chrome Initialization Complete
Chrome版本:78.0.3904.87

Chromedriver版本:Chromedriver_78.0.3904.70

Selenium版本:3.141.59

虽然这个问题不是一个主要障碍,但它打开了第二个chrome实例,在待机状态下会消耗内存,这有点令人恼火


干杯

有几件事你需要注意:

此错误消息

Nov 04, 2019 3:29:38 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Attempting bi-dialect session, assuming Postel's Law holds true on the remote end
Nov 04, 2019 3:29:43 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Falling back to original OSS JSON Wire Protocol.
[1572910186.002][WARNING]: Timed out connecting to Chrome, retrying...
Nov 04, 2019 3:29:48 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: OSS
…意味着ChromeDriver无法启动/生成新的网络浏览器,即Chrome浏览器会话

根据讨论,该问题是在2016-09-01 14:57:03-0700发布的Selenium Client v3.0.0-beta3上观察到的

西蒙在一篇文章中提到:

根本原因是ClassCastException。现在,我们捕获该异常,记录我们试图解析的内容,并继续进行其他尝试以完成握手。该修复程序在Selenium Client v3.0.0-beta4中提供。

最合适的解决办法是:

  • 将Selenium升级到当前的级别
您可以在中找到详细的讨论


下一个错误消息

Nov 04, 2019 3:29:38 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Attempting bi-dialect session, assuming Postel's Law holds true on the remote end
Nov 04, 2019 3:29:43 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Falling back to original OSS JSON Wire Protocol.
[1572910186.002][WARNING]: Timed out connecting to Chrome, retrying...
Nov 04, 2019 3:29:48 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: OSS
…还意味着您使用的ChromeDriver/Chrome浏览器组合不是最新的组合,因为ChromeDriver的当前实现遵循W3C,初始日志如下所示:

Starting ChromeDriver 78.0.3904.70 (edb9c9f3de0247fd912a77b7f6cae7447f6d3ad5-refs/branch-heads/3904@{#800}) on port 9626
Only local connections are allowed.
Please protect ports used by ChromeDriver and related test frameworks to prevent access by malicious code.
Nov 05, 2019 3:41:53 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: W3C

解决方案 确保:

  • JDK已升级到当前级别
  • 硒被提升到当前水平
  • ChromeDriver已更新到当前级别
  • Chrome更新到当前的Chrome版本78.0级别。(根据)
  • 通过IDE清理项目工作区,并仅使用所需的依赖项重建项目
  • (仅限Windows OS)在执行测试套件之前和之后,使用该工具清除所有操作系统杂务
  • (仅限LinuxOS)在执行测试套件之前和之后
  • 如果您的基本Web客户端版本太旧,请卸载它并安装最新的GA和Web客户端发布版本
  • 重新启动系统
  • 以非root用户身份执行
    @Test
  • 始终在
    tearDown(){}
    方法中调用
    driver.quit()
    ,以优雅地关闭和销毁Web驱动程序和Web客户端实例

工具书类 您可以在以下内容中找到一些相关讨论:


奥特罗 根据本文,Selenium v3.0.1的
协议握手.java
文件中的
createSession()
包含以下内容:

public Result createSession(HttpClient client, Command command)
    throws IOException {
    // Avoid serialising the capabilities too many times. Things like profiles are expensive.

    Capabilities desired = (Capabilities) command.getParameters().get("desiredCapabilities");
    desired = desired == null ? new DesiredCapabilities() : desired;
    Capabilities required = (Capabilities) command.getParameters().get("requiredCapabilities");
    required = required == null ? new DesiredCapabilities() : required;

    String des = new BeanToJsonConverter().convert(desired);
    String req = new BeanToJsonConverter().convert(required);

    // Assume the remote end obeys the robustness principle.
    StringBuilder parameters = new StringBuilder("{");
    amendW3CParameters(parameters, des, req);
    parameters.append(",");
    amendOssParamters(parameters, des, req);
    parameters.append("}");
    LOG.info("Attempting bi-dialect session, assuming Postel's Law holds true on the remote end");
    Optional result = createSession(client, parameters);

    // Assume a fragile OSS webdriver implementation
    if (!result.isPresent()) {
      parameters = new StringBuilder("{");
      amendOssParamters(parameters, des, req);
      parameters.append("}");
      LOG.info("Falling back to original OSS JSON Wire Protocol.");
      result = createSession(client, parameters);
    }

    // Assume a fragile w3c implementation
    if (!result.isPresent()) {
      parameters = new StringBuilder("{");
      amendW3CParameters(parameters, des, req);
      parameters.append("}");
      LOG.info("Falling back to straight W3C remote end connection");
      result = createSession(client, parameters);
    }

    if (result.isPresent()) {
      Result toReturn = result.get();
      LOG.info(String.format("Detected dialect: %s", toReturn.dialect));
      return toReturn;
    }

    throw new SessionNotCreatedException(
      String.format(
        "Unable to create new remote session. " +
        "desired capabilities = %s, required capabilities = %s",
        desired,
        required));
}

您需要注意以下几件事:

此错误消息

Nov 04, 2019 3:29:38 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Attempting bi-dialect session, assuming Postel's Law holds true on the remote end
Nov 04, 2019 3:29:43 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Falling back to original OSS JSON Wire Protocol.
[1572910186.002][WARNING]: Timed out connecting to Chrome, retrying...
Nov 04, 2019 3:29:48 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: OSS
…意味着ChromeDriver无法启动/生成新的网络浏览器,即Chrome浏览器会话

根据讨论,该问题是在2016-09-01 14:57:03-0700发布的Selenium Client v3.0.0-beta3上观察到的

西蒙在一篇文章中提到:

根本原因是ClassCastException。现在,我们捕获该异常,记录我们试图解析的内容,并继续进行其他尝试以完成握手。该修复程序在Selenium Client v3.0.0-beta4中提供。

最合适的解决办法是:

  • 将Selenium升级到当前的级别
您可以在中找到详细的讨论


下一个错误消息

Nov 04, 2019 3:29:38 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Attempting bi-dialect session, assuming Postel's Law holds true on the remote end
Nov 04, 2019 3:29:43 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Falling back to original OSS JSON Wire Protocol.
[1572910186.002][WARNING]: Timed out connecting to Chrome, retrying...
Nov 04, 2019 3:29:48 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: OSS
…还意味着您使用的ChromeDriver/Chrome浏览器组合不是最新的组合,因为ChromeDriver的当前实现遵循W3C,初始日志如下所示:

Starting ChromeDriver 78.0.3904.70 (edb9c9f3de0247fd912a77b7f6cae7447f6d3ad5-refs/branch-heads/3904@{#800}) on port 9626
Only local connections are allowed.
Please protect ports used by ChromeDriver and related test frameworks to prevent access by malicious code.
Nov 05, 2019 3:41:53 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: W3C

解决方案 确保:

  • JDK已升级到当前级别
  • 硒被提升到当前水平
  • ChromeDriver已更新到当前级别
  • Chrome更新到当前的Chrome版本78.0级别。(根据)
  • 通过IDE清理项目工作区,并仅使用所需的依赖项重建项目
  • (仅限Windows OS)在执行测试套件之前和之后,使用该工具清除所有操作系统杂务
  • (仅限LinuxOS)在执行测试套件之前和之后
  • 如果您的基本Web客户端版本太旧,请卸载它并安装最新的GA和Web客户端发布版本
  • 重新启动系统
  • 以非root用户身份执行
    @Test
  • 始终在
    tearDown(){}
    方法中调用
    driver.quit()
    ,以优雅地关闭和销毁Web驱动程序和Web客户端实例

工具书类 您可以在以下内容中找到一些相关讨论:


奥特罗 根据本文,Selenium v3.0.1的
协议握手.java
文件中的
createSession()
包含以下内容:

public Result createSession(HttpClient client, Command command)
    throws IOException {
    // Avoid serialising the capabilities too many times. Things like profiles are expensive.

    Capabilities desired = (Capabilities) command.getParameters().get("desiredCapabilities");
    desired = desired == null ? new DesiredCapabilities() : desired;
    Capabilities required = (Capabilities) command.getParameters().get("requiredCapabilities");
    required = required == null ? new DesiredCapabilities() : required;

    String des = new BeanToJsonConverter().convert(desired);
    String req = new BeanToJsonConverter().convert(required);

    // Assume the remote end obeys the robustness principle.
    StringBuilder parameters = new StringBuilder("{");
    amendW3CParameters(parameters, des, req);
    parameters.append(",");
    amendOssParamters(parameters, des, req);
    parameters.append("}");
    LOG.info("Attempting bi-dialect session, assuming Postel's Law holds true on the remote end");
    Optional result = createSession(client, parameters);

    // Assume a fragile OSS webdriver implementation
    if (!result.isPresent()) {
      parameters = new StringBuilder("{");
      amendOssParamters(parameters, des, req);
      parameters.append("}");
      LOG.info("Falling back to original OSS JSON Wire Protocol.");
      result = createSession(client, parameters);
    }

    // Assume a fragile w3c implementation
    if (!result.isPresent()) {
      parameters = new StringBuilder("{");
      amendW3CParameters(parameters, des, req);
      parameters.append("}");
      LOG.info("Falling back to straight W3C remote end connection");
      result = createSession(client, parameters);
    }

    if (result.isPresent()) {
      Result toReturn = result.get();
      LOG.info(String.format("Detected dialect: %s", toReturn.dialect));
      return toReturn;
    }

    throw new SessionNotCreatedException(
      String.format(
        "Unable to create new remote session. " +
        "desired capabilities = %s, required capabilities = %s",
        desired,
        required));
}

从您包含的日志来看,它似乎没有创建2个chromes实例。你能再增加一点上下文吗?它不会创建两个chrome实例。由于Log4j初始化未正确完成,因此它正在重新尝试连接。从您包含的日志来看,它似乎没有创建2个chromes实例。你能再增加一点上下文吗?它不会创建两个chrome实例。由于Log4j初始化未正确完成,因此正在重试连接。完成,再次感谢:)完成,再次感谢:)