org.openqa.selenium.WebDriverException:转发新会话时出错,找不到:功能 [英] org.openqa.selenium.WebDriverException: Error forwarding the new session cannot find : Capabilities

查看:32
本文介绍了org.openqa.selenium.WebDriverException:转发新会话时出错,找不到:功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

集线器启动命令:

java -jar selenium-server-standalone-3.11.0.jar -role hub

节点启动命令:

java -Dwebdriver.chrome.driver=/Users/alina/Selenium/chromedriver.exe  -jar selenium-server-standalone-3.11.0.jar -role webdriver -hub http://192.168.100.4:4444/grid/register/

环境详细信息(根据评论更新):Selenium 3.11.0、Chrome 66、ChromeDriver 2.38

Environment Details (updated from comments) : Selenium 3.11.0, Chrome 66, ChromeDriver 2.38

import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.Platform;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;

public class TestGrid {
 static WebDriver driver;
 static String nodeUrl;

public static void main(String[] args)
{

try {

    nodeUrl = "http://192.168.100.4:4444/wd/hub";
    DesiredCapabilities capabilities = DesiredCapabilities.chrome();
    capabilities.setPlatform(Platform.SIERRA);
    driver = new RemoteWebDriver(new URL(nodeUrl), capabilities);
    driver.manage().deleteAllCookies();
    driver.manage().window().maximize();
    driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
    driver.manage().timeouts().pageLoadTimeout(45, TimeUnit.SECONDS);
    driver.get("http://www.amazon.com");
    driver.findElement(By.linkText("Today's Deals")).click();


} catch (MalformedURLException e) {
    e.printStackTrace();
}

}

当我尝试运行它时,我得到了这个错误:

When I try to run it, I get this error:

Apr 24, 2018 4:14:34 PM org.openqa.selenium.remote.DesiredCapabilities chrome
INFO: Using `new ChromeOptions()` is preferred to    `DesiredCapabilities.chrome()`
Exception in thread "main" org.openqa.selenium.WebDriverException: Error forwarding the new session cannot find : Capabilities {browserName: chrome, platform: macOS 10.12, version: }
Command duration or timeout: 90 milliseconds
Build info: version: '3.11.0', revision: 'e59cfb3', time: '2018-03-11T20:33:08.638Z'
System info: host: 'Alinas-MacBook-Pro.local', ip: '2a02:2f0e:1a0:5d9:95f0:9fb4:dfea:28c7%en0', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.13.4', java.version: '10.0.1'
Driver info: driver.version: RemoteWebDriver
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:488)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:214)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:166)
at org.openqa.selenium.remote.JsonWireProtocolResponse.lambda$new$0(JsonWireProtocolResponse.java:53)
at org.openqa.selenium.remote.JsonWireProtocolResponse.lambda$getResponseFunction$2(JsonWireProtocolResponse.java:91)
at org.openqa.selenium.remote.ProtocolHandshake.lambda$createSession$0(ProtocolHandshake.java:123)
at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:195)
at java.base/java.util.Spliterators$ArraySpliterator.tryAdvance(Spliterators.java:958)
at java.base/java.util.stream.ReferencePipeline.forEachWithCancel(ReferencePipeline.java:127)
at java.base/java.util.stream.AbstractPipeline.copyIntoWithCancel(AbstractPipeline.java:502)
at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:488)
at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474)
at java.base/java.util.stream.FindOps$FindOp.evaluateSequential(FindOps.java:150)
at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.base/java.util.stream.ReferencePipeline.findFirst(ReferencePipeline.java:543)
at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:126)
at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:73)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:136)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:545)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:209)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:132)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:145)
at grid.TestGrid.main(TestGrid.java:26)
Caused by: org.openqa.grid.common.exception.GridException: Error forwarding the new session cannot find : Capabilities {browserName: chrome, platform: macOS 10.12, version: }
at org.openqa.grid.web.servlet.handler.RequestHandler.process(RequestHandler.java:118)
at org.openqa.grid.web.servlet.DriverServlet.process(DriverServlet.java:86)
at org.openqa.grid.web.servlet.DriverServlet.doPost(DriverServlet.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
at org.seleniumhq.jetty9.servlet.ServletHolder.handle(ServletHolder.java:860)
at org.seleniumhq.jetty9.servlet.ServletHandler.doHandle(ServletHandler.java:535)
at org.seleniumhq.jetty9.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:188)
at org.seleniumhq.jetty9.server.session.SessionHandler.doHandle(SessionHandler.java:1595)
at org.seleniumhq.jetty9.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:188)
at org.seleniumhq.jetty9.server.handler.ContextHandler.doHandle(ContextHandler.java:1253)
at org.seleniumhq.jetty9.server.handler.ScopedHandler.nextScope(ScopedHandler.java:168)
at org.seleniumhq.jetty9.servlet.ServletHandler.doScope(ServletHandler.java:473)
at org.seleniumhq.jetty9.server.session.SessionHandler.doScope(SessionHandler.java:1564)
at org.seleniumhq.jetty9.server.handler.ScopedHandler.nextScope(ScopedHandler.java:166)
at org.seleniumhq.jetty9.server.handler.ContextHandler.doScope(ContextHandler.java:1155)
at org.seleniumhq.jetty9.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
at org.seleniumhq.jetty9.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132)
at org.seleniumhq.jetty9.server.Server.handle(Server.java:530)
at org.seleniumhq.jetty9.server.HttpChannel.handle(HttpChannel.java:347)
at org.seleniumhq.jetty9.server.HttpConnection.onFillable(HttpConnection.java:256)
at org.seleniumhq.jetty9.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:279)
at org.seleniumhq.jetty9.io.FillInterest.fillable(FillInterest.java:102)
at org.seleniumhq.jetty9.io.ChannelEndPoint$2.run(ChannelEndPoint.java:124)
at org.seleniumhq.jetty9.util.thread.strategy.EatWhatYouKill.doProduce(EatWhatYouKill.java:247)
at org.seleniumhq.jetty9.util.thread.strategy.EatWhatYouKill.produce(EatWhatYouKill.java:140)
at org.seleniumhq.jetty9.util.thread.strategy.EatWhatYouKill.run(EatWhatYouKill.java:131)
at org.seleniumhq.jetty9.util.thread.ReservedThreadExecutor$ReservedThread.run(ReservedThreadExecutor.java:382)
at org.seleniumhq.jetty9.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:708)
at org.seleniumhq.jetty9.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:626)
at java.lang.Thread.run(Thread.java:844)

有谁知道我做错了什么?

Does anyone know what am I doing wrong?

推荐答案

这个错误信息...

Exception in thread "main" org.openqa.selenium.WebDriverException: Error forwarding the new session cannot find : Capabilities {browserName: chrome, platform: macOS 10.12, version: }

...暗示 ChromeDriver 无法启动与 WebClient 的活动连接,即 Chrome 浏览器.

...implies that the ChromeDriver wasn't able to initiate an active connection with the WebClient i.e Chrome browser.

您的主要问题是您使用的二进制文件之间的版本兼容性,如下所示:

Your main issue is the version compatibility between the binaries you are using as follows :

  • 您正在使用 chromedriver=2.36
  • chromedriver=2.36 的发行说明明确提及以下内容:

支持 Chrome v63-65

  • 您正在使用 chrome=66.0
  • ChromeDriver v2.38 明确提及以下内容:
  • 支持 Chrome v65-67

    所以 ChromeDriver 版本 (v2.36) 和 Chrome 浏览器 版本 (v66.0)

    So there is a clear mismatch between the ChromeDriver version (v2.36) and the Chrome Browser version (v66.0)

    • ChromeDriver 升级到当前的 ChromeDriverv2.38 级别.
    • Chrome 版本保持在 Chrome v66.x 级别.(根据 ChromeDriver v2.38 发行说明)
    • 清理你的项目工作区通过你的IDE重建你的项目只需要依赖.
    • 使用 CCleaner 工具清除之前和在您的测试套件执行之后.
    • 如果您的基础 Web Client 版本太旧,请通过 卸载它Revo Uninstaller 并安装最新的 GA 和发布版本的 Web Client.
    • 进行一次系统重启.
    • 执行你的 @Test.
    • Upgrade ChromeDriver to current ChromeDriver v2.38 level.
    • Keep Chrome version at Chrome v66.x levels. (as per ChromeDriver v2.38 release notes)
    • Clean your Project Workspace through your IDE and Rebuild your project with required dependencies only.
    • Use CCleaner tool to wipe off all the OS chores before and after the execution of your test Suite.
    • If your base Web Client version is too old, then uninstall it through Revo Uninstaller and install a recent GA and released version of Web Client.
    • Take a System Reboot.
    • Execute your @Test.

    根据您在使用 Selenium 3.x 时的问题更新,您需要将关键字 webdriver 替换为 node 并删除扩展名(WebDriver 变体的 .exe) 如下:

    As per your question update while working with Selenium 3.x you need to replace the keyword webdriver with node and remove the extension (.exe) of the WebDriver variant as follows :

    • Mac OS X:

    java -Dwebdriver.chrome.driver=/Users/alina/Selenium/chromedriver -jar selenium-server-standalone-3.11.0.jar -role node -hub http://192.168.100.4:4444/grid/register/
    

    由于您仍然面临同样的错误,让我们解决错误:

    As you are still facing the same error let us address the error :

    Using `new ChromeOptions()` is preferred to    `DesiredCapabilities.chrome()`
    

    根据错误消息,您需要使用 merge() 方法来自 MutableCapabilities 类合并DesiredCapabilities 类型的对象转换为 ChromeOptions 类型的对象,并通过传递 ChromeOptions 对象来启动 RemoteWebDriverWebClient 实例如下:

    As per the error message you need to use the merge() method from MutableCapabilities Class to merge the DesiredCapabilities type of object into ChromeOptions type object and initiate the RemoteWebDriver and WebClient instance by passing the ChromeOptions object as follows :

    System.setProperty("webdriver.chrome.driver", "/Users/username/chromedriver");
    nodeUrl = "http://192.168.100.4:4444/wd/hub";
    DesiredCapabilities capabilities = DesiredCapabilities.chrome();
    capabilities.setPlatform(Platform.SIERRA);
    ChromeOptions options = new ChromeOptions();
    options.merge(capabilities);
    driver = new RemoteWebDriver(new URL(nodeUrl), options);
    driver.get("http://www.amazon.com");
    

    PS:作为参考,您可以查看 mutablecapabilities 中的讨论强>标签

    PS : As a reference you can have a look at the discussions in mutablecapabilities tag

    这篇关于org.openqa.selenium.WebDriverException:转发新会话时出错,找不到:功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆