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

org.openqa.selenium.WebDriverException:错误转发新会话找不到:能力

高溪叠
2023-03-14

轮毂启动命令:

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

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();
}

}

当我尝试运行它时,会出现以下错误:

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)

有人知道我做错了什么吗?

共有1个答案

严兴言
2023-03-14

此错误消息...

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活动连接。

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

  • 您使用的是chromedriver=2.36
  • chromedriver=2.36的发行说明明确提到以下内容:

支持Chromev63-65

  • 您使用的是chrome=66.0

支持Chromev65-67

因此ChromeDriver版本(v2.36)和Chrome浏览器版本(v66.0)之间存在明显的不匹配

  • 将ChromeDriver升级到当前的ChromeDriver v2.38版本

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

>

  • 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/
    

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

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

    根据错误消息,您需要使用MutableCaptions类中的mer()方法将对象的DesiredCaptions类型合并到ChromeOptions类型对象中,并通过传递ChromeOptions对象来启动Remote teWebDriver和WebClient实例,如下所示:

    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:作为参考,您可以查看标签中的讨论

  •  类似资料:
    • 我安装了视窗10-64,火狐61.0.2,Java。我正在执行我的测试与硒网格和selenium-server-standalone-3.11.0.jar,和geckoDrive21.0,但当我运行它,测试显示以下错误: org.openqa.selenium.WebDriverExc0019:错误转发新会话找不到:功能{接受InsecureCerts: true,浏览器名称: Firefox,平

    • 我的selenium配置有问题。我正在尝试在iOS和Android上自动化Selenium测试。 iOS测试独立于iOS驱动程序正常运行。Android测试也在独立正常运行。 但是当我想运行iOS和Android时,我遇到了问题! 对于我的Android测试,我正在运行这个命令,一切都很好: 但是,当我想要集成iOS测试时,我会按照以下指南更改此命令的端口:http://selendroid.io

    • 我正在使用:Java:1.8 Selenium:3.141.59 jar Geco驱动程序版本:0.25.0 Firefox版本:69.0.1 在运行代码时获得以下异常日志: org.openqa.selenium.WebDriverException:为安装功能转发VM的新会话空池时出错{AcceptinSecureCerts:true,BrowserName:firefox,Marionett

    • 我正在使用Selenium Grid。我最近将VM(node)更新到Windows 10,它不再工作了。以下是详细信息 我通过以下方式将此VM Win10注册为网格节点: (这之前与VM Win8一起工作得很好)我可以在网格上看到这个VM Win10注册了3个浏览器IE11、FF和Chrome 在我的代码中,我通过以下方式创建web驱动程序: 我总是得到这个错误当我执行测试 转发新会话时出错,无法

    • 我最近安装了一个用于开发测试的selenium网格环境。然而,我们面临以下错误: 转发新会话时出错,无法找到:功能{browserName:chrome,chromeOptions:{args:[--headless,--no sandbox],二进制:,首选项:{plugins.always\u open\u pdf\u externally:true},w3c:false},loggingPr

    • OS:LinuxSelenium版本:**3.12**浏览器:ChromeV66, chromeDrive2.38 以下是我的网格配置:集线器(Linux)运行在詹金斯机器(https://jenkins.us.abc.edu)上,带有硒网格詹金斯插件。 现在,我尝试使用json注册我的节点,如下所示,并启动节点:java-jar-Dwebdriver。铬。驱动程序=chromedriver se