System.InvalidOperationException未得到处理HResult=-2146233079消息=无



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

java -jar C:UsersFlcUserDownloadsselenium-server-standalone-3.141.5.jar -role hub -host 10.1.1.14
java -Dwebdrive.chrome.drive="C:Tempchromedriver.exe" -jar C:Tempselenium-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:SeleniumDemoSeleniumPruebaProgram.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中的库。

我该如何解决这个问题?

问题似乎出现在用于启动硒网格节点的命令中,而不是:

java -Dwebdrive.chrome.drive="C:Tempchromedriver.exe" -jar C:Tempselenium-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/

相关内容

  • 没有找到相关文章

最新更新