0

我在使用 Selenium 4 从 Csharp 的 Visual Studio 运行 Selenium Grid 时遇到问题。我不断收到错误消息:

信息:

System.InvalidOperationException : Could not start a new session. Could not start a new session. Error while creating session with the driver service. Stopping driver service: Driver server process died prematurely.
Build info: version: '4.1.1', revision: 'e8fcc2cecf'
System info: host: 'ATTPA-1450', ip: '172.26.0.1', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '11.0.12'
Driver info: driver.version: unknown
Build info: version: '4.1.1', revision: 'e8fcc2cecf'
System info: host: 'ATTPA-1450', ip: '172.26.0.1', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '11.0.12'
Driver info: driver.version: unknown
Build info: version: '4.1.1', revision: 'e8fcc2cecf'
System info: host: 'ATTPA-1450', ip: '172.26.0.1', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '11.0.12'
Driver info: driver.version: unknown (SessionNotCreated)
TearDown : System.NullReferenceException : Object reference not set to an instance of an object.

堆栈跟踪:

WebDriver.UnpackAndThrowOnError(Response errorResponse)
WebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
WebDriver.StartSession(ICapabilities desiredCapabilities)
WebDriver.ctor(ICommandExecutor executor, ICapabilities capabilities)
RemoteWebDriver.ctor(ICommandExecutor commandExecutor, ICapabilities desiredCapabilities)
RemoteWebDriver.ctor(Uri remoteAddress, ICapabilities desiredCapabilities, TimeSpan commandTimeout)
WebDriverFactory.OpenBrowser() line 28
BaseTest.Test_Setup() line 54*

你能告诉我我错过了什么吗?我从这个位置下载了 .jar 文件 - https://www.selenium.dev/downloads/

我在本地机器上启动了 selenium hub: 在此处输入图像描述

然后我在这里注册了 selenium 节点: 在此处输入图像描述

我确保我可以在这里进入网格: 在此处输入图像描述

这是我的代码(我最初使用 http://localhost:4444/wd/hub)但仍然遇到相同的错误: 在此处输入图像描述

当我将代码更改为

我收到这个错误

_driver = new RemoteWebDriver(new Uri("http://localhost:4444/wd/hub"), browserOptions);

信息:

OpenQA.Selenium.WebDriverException : The HTTP request to the remote WebDriver server for URL http://localhost:4444/wd/hub/session timed out after 60 seconds.
  ----> System.Threading.Tasks.TaskCanceledException : The operation was canceled.
  ----> System.IO.IOException : Unable to read data from the transport connection: The I/O operation has been aborted because of either a thread exit or an application request..
  ----> System.Net.Sockets.SocketException : The I/O operation has been aborted because of either a thread exit or an application request.
TearDown : System.NullReferenceException : Object reference not set to an instance of an object.*
4

1 回答 1

0

此错误消息...

System.InvalidOperationException : Could not start a new session. Could not start a new session. Error while creating session with the driver service. Stopping driver service: Driver server process died prematurely.
Build info: version: '4.1.1', revision: 'e8fcc2cecf'
System info: host: 'ATTPA-1450', ip: '172.26.0.1', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '11.0.12'
Driver info: driver.version: unknown

...意味着ChromeDriver无法启动/产生新的浏览上下文,即Chrome 浏览器会话。

可能您的主要问题是您使用的二进制文件版本之间的不兼容,因为未检测到ChromeDriver版本:

Driver info: driver.version: unknown

解决方案

确保这件事:

于 2022-01-17T19:52:28.663 回答