selenium icon indicating copy to clipboard operation
selenium copied to clipboard

Unable To Create Remote WebDriver instance in c# nuget version 3.4.0

Open randersen opened this issue 9 years ago • 9 comments

Meta -

OS:
Windows 10 Selenium Version:
3.4.0 C# Nuget package Selenium Standalone Server version 3.3.1 Browser:
Chrome

Browser Version:
57.0.2987.133 64-bit

Expected Behavior -

Calling new RemoteWebDriver(Uri, chromeCapabilities);

creates a new chrome webdriver instance

Actual Behavior -

Instantiating a RemoteWebdriver throws a blank exception with no details whatsoever immediately.

Steps to reproduce -

Install selenium 3.4.0 nuget package in c# Start a Grid Hub and Node using Selenium Stand Alone Server version 3.3.1 Attempt to instantiate a new RemoteWebDriver with the following capabilities with the URI set to the hub created above . var chromeCapabilities = DesiredCapabilities.Chrome(); chromeCapabilities.SetCapability("chrome.binary", "FILEPATH"); chromeCapabilities.SetCapability("webdriver.chrome.driver", "FILEPATH");

Notice an exception is thrown but there is no exception message or inner exception

randersen avatar Apr 27 '17 19:04 randersen

I'm also facing it with IE options:

var ieOptions = new InternetExplorerOptions(); ieOptions.UnexpectedAlertBehavior = InternetExplorerUnexpectedAlertBehavior.Accept; ieOptions.RequireWindowFocus = true; ieOptions.EnableNativeEvents = true; ieOptions.IgnoreZoomLevel = true; var driver = new RemoteWebDriver(Config.WebDriver.RemoteUrl, ieOptions);

Bakanych avatar Apr 28 '17 09:04 Bakanych

This is an issue in the grid itself, not in the .NET bindings. The new session command is being sent the following payload:

{
  "desiredCapabilities":{
    "browserName":"internet explorer",
    "version":"",
    "platform":"ANY",
    "javascriptEnabled":true
  },
  "capabilities":{
    "firstMatch":[{
      "browserName":"chrome"
    }]
  }
}

This is a perfectly valid payload for a new session command. The response is thus:

{
  "status":13,
  "value":{
    "class":"java.lang.NullPointerException",
    "stackTrace":[ {
        "fileName":"HashMap.java",
        "className":"java.util.HashMap",
        "methodName":"putMapEntries",
        "lineNumber":500
      },{
        "fileName":"HashMap.java",
        "className":"java.util.HashMap",
        "methodName":"putAll",
        "lineNumber":784
      },{
        "fileName":"DesiredCapabilities.java",
        "className":"org.openqa.selenium.remote.DesiredCapabilities",
        "methodName":"\u003cinit\u003e",
        "lineNumber":55
      },{
        "fileName":"RequestHandler.java",
        "className":"org.openqa.grid.web.servlet.handler.RequestHandler",
        "methodName":"process",
        "lineNumber":104
      },
      ... <additional stack frames deleted for brevity>
    ]
  }
}

Note the lack of a message property on the JSON response, which is a violation of both the W3C and OSS dialects of the wire protocol, and is why there is no message associated with the thrown exception. Nevertheless, it appears that attempting to initialize the capabilities in the hub is where the issue ultimately is. This will need investigation in the grid hub code.

jimevans avatar Apr 29 '17 18:04 jimevans

After a little further investigation, the actual logic error appears to be in org.openqa.grid.web.servlet.handler.WebDriverRequest.extractDesiredCapability() (located at line 62 in java/server/src/org/openqa/grid/web/servlet/handler/WebDriverRequest.java). That method assumes that if a new session request has a capabilities property, the desired capabilities must be contained somewhere therein. This is not necessarily the case, as a local end should be sending new session requests that are compatible with both protocol dialects (i.e., { "capabilities": {...}, "desiredCapabilities": {...} }), and detecting the appropriate dialect from the response. This new session payload approach works perfectly when running against a remote end that is an end node (like chromedriver.exe, geckodriver.exe, or IEDriverServer.exe), and even works when using the standalone server directly. It only fails when sending the request to a grid hub to request a new session on one of the nodes.

Pinging @shs96c on this comment, since it's likely he'll get around to fixing it before I will, but if someone like @barancev, @lukeis, or @mach6 wanted to take a stab at fixing this, I wouldn't be upset about it.

jimevans avatar Apr 29 '17 18:04 jimevans

This is a duplicate of #3808 it appears

lmtierney avatar Apr 29 '17 19:04 lmtierney

Then let's close this one.

jimevans avatar Apr 29 '17 19:04 jimevans

Do we have any work around of it?

sajidchingchong avatar May 04 '17 08:05 sajidchingchong

@sajidchingchong I downgraded selenium to 3.3.0 and it works fine

randersen avatar May 04 '17 15:05 randersen

Actually I was working with 3.3.1 before. I needed to upgrade to 3.4.0 since sendKeys() on Firefox was not working in 3.3.1

When you say you downgraded to 3.3.0, does it mean you downgraded selenium-java client API or only the hub/node?

sajidchingchong avatar May 05 '17 02:05 sajidchingchong

I downgraded the client, they will need to put out a new selenium standalone in order for this to work with 3.4.0

randersen avatar May 05 '17 17:05 randersen