未处理System.InvalidOperationException HResult = -2146233079消息=无法创建新服务:ChromeDriverService

时间:2018-11-15 17:06:28

标签: c# selenium selenium-webdriver selenium-chromedriver selenium-grid

我正在尝试使用Selenium Grid和C#远程控制chrome浏览器。它曾经可以工作,但是由于我在机器B上安装了新的Windows映像,因此不再可用。但是,我可以在两台计算机上本地使用Selenium,因此我认为这不是chromedriver问题。对于远程控制,我分别在机器A和机器B中运行以下命令:

java -jar C:\Users\FlcUser\Downloads\selenium-server-standalone-3.141.5.jar -role hub -host 10.1.1.14

java -Dwebdrive.chrome.drive="C:\Temp\chromedriver.exe" -jar C:\Temp\selenium-server-standalone-3.141.5.jar -role node -hub http://10.1.1.14:4444/grid/register

该节点已成功注册,然后运行此C#代码(我不知道我所评论的内容是否必要,但它不会更改错误):

ChromeOptions options = new ChromeOptions();
        //options.BinaryLocation = "C:\\Temp\\chromedriver.exe";
        IWebDriver driver = new RemoteWebDriver(new Uri("http://10.1.1.14:4444/wd/hub"), options.ToCapabilities(), TimeSpan.FromSeconds(180));

我收到“无法创建新服务:ChromeDriverService”错误。我已经阅读了很多,并且尝试了很多事情。我更新了所有内容。我确保我的chromedriver版本与我的浏览器兼容,并且我还拥有Java的最新版本(两台机器上均为https://java.com/en/download/)。

这是我在cmd中获得的日志:

机器A:

17:48:23.746 INFO [DefaultGridRegistry.add] - Registered a node http://10.24.25.237:19016
17:50:19.814 INFO [RequestHandler.process] - Got a request to create a new session: Capabilities {browserName: chrome, goog:chromeOptions: {}}
17:50:35.155 INFO [TestSlot.getNewSession] - Trying to create a new session on test slot {server:CONFIG_UUID=2dac93b3-8952-4c62-bcee-3c5febe21545, seleniumProtocol=WebDriver, browserName=chrome, maxInstances=5, platformName=WIN10, platform=WIN10}

机器B:

21:48:31.497 INFO [ActiveSessionFactory.apply] - Capabilities are: {
"browserName": "chrome",
"goog:chromeOptions": {}}
21:48:31.497 INFO [ActiveSessionFactory.lambda$apply$11] - Matched factory org.openqa.selenium.grid.session.remote.ServicedSession$Factory (provider: org.openqa.selenium.chrome.ChromeDriverService)

这是Visual Studio抛出的异常:

System.InvalidOperationException was unhandled
  HResult=-2146233079
  Message=Unable to create new service: ChromeDriverService
Build info: version: '3.141.5', revision: 'd54ebd709a', time: '2018-11-06T11:58:47'
System info: host: 'FLCOMPACT', ip: '10.1.1.25', os.name: 'Windows 10', os.arch: 'x86', os.version: '10.0', java.version: '1.8.0_191'
Driver info: driver.version: unknown (SessionNotCreated)
  Source=WebDriver
  StackTrace:
       at OpenQA.Selenium.Remote.RemoteWebDriver.UnpackAndThrowOnError(Response errorResponse)
       at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
       at OpenQA.Selenium.Remote.RemoteWebDriver.StartSession(ICapabilities desiredCapabilities)
       at OpenQA.Selenium.Remote.RemoteWebDriver..ctor(ICommandExecutor commandExecutor, ICapabilities desiredCapabilities)
       at OpenQA.Selenium.Remote.RemoteWebDriver..ctor(Uri remoteAddress, ICapabilities desiredCapabilities, TimeSpan commandTimeout)
       at SeleniumPrueba.Program.Main(String[] args) in d:\SeleniumDemo\SeleniumPrueba\Program.cs:line 21
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException: 

最后,我在其他计算机上尝试了相同的操作,但遇到了相同的错误,所以我做错了。我认为它与Java或chromedriver有关,因为我曾经运行此VS代码解决方案而没有问题。顺便说一句,我还通过NuGet更新了Visual Studio中的库。

有人可以帮我吗?

多谢您的时间。

1 个答案:

答案 0 :(得分:0)

问题似乎出在您用来启动 Selenium Grid Node 的命令中,而不是:

java -Dwebdrive.chrome.drive="C:\Temp\chromedriver.exe" -jar C:\Temp\selenium-server-standalone-3.141.5.jar -role node -hub http://10.1.1.14:4444/grid/register

应该是:

java -Dwebdriver.chrome.driver=C:/Temp/chromedriver.exe -jar C:/Temp/selenium-server-standalone-3.141.5.jar -role node -hub http://10.1.1.14:4444/grid/register

注释A 密钥 webdriver.chrome.driver ,而不是webdrive.chrome.drive

注释B :确保网格节点上的 ChromeDriver 二进制文件位于C:/Temp/