2

I've been searching for the correct documentation on how to use ChromeOptions and DesiredCapabilities in the atmosphere of Selenium and C#, but since it's all open sourced, I only find suggestions (and they are not helping sometimes). My question today is how to setup the correct relation between ChromeOptions and DesiredCapabilities. Seems like I'm doing everything correctly, but still getting System.InvalidOperationException: unknown error:cannot parse capability: chromeOptions from unknown error: unrecognized chrome option:Arguments My code is following:

 private static ChromeOptions Ops()
        {
            var options = new ChromeOptions();
            options.AddArgument("--no-startup-window");
            options.BinaryLocation = @"C:\path\path\path\chromedriver.exe";
            return options;
        }
  private static DesiredCapabilities Caps()
        {
            DesiredCapabilities caps = new DesiredCapabilities();
            caps.SetCapability(CapabilityType.BrowserName, "chrome");
            caps.SetCapability(ChromeOptions.Capability,Ops().ToCapabilities());
            return caps;
        }
IWebDriver driver = new RemoteWebDriver(new Uri("http://localhost:4444/wd/hub"), Caps());

Can't find a place where incorrect Arguments are passing. Has anybody faced the same issues? This is ChromeDriver version 2.28 and selenium WebDriver v 3.3.0 Google Chrome browser version is 52.

President
  • 37
  • 1
  • 7

1 Answers1

1

You don't need to set the browser name; ChromeOptions does that for you.

According to this comment

The .NET bindings are moving toward a pattern where DesiredCapabilites should not be used directly, even with RemoteWebDriver. To facilitate that, the ChromeOptions class has a ToCapabilities() method

And there's this comment

Much like --disable-javascript, the chromedriver will not work if you use --no-startup-window. It needs to launch a window to establish the connection with the AutomationProxy.

So that gets us to this:

var options = new ChromeOptions();
options.BinaryLocation = @"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe";

IWebDriver driver = new RemoteWebDriver(new Uri("http://localhost:4444/wd/hub"), options.ToCapabilities());

However, are you actually running a grid? If you're testing on a single machine it's even simpler:

IWebDriver driver = new ChromeDriver();
Mark Lapierre
  • 1,067
  • 9
  • 15