Setting BrowserExecutableLocation in FirefoxOptions in Selenium doesn't prevent an "Unable to find a matching set of capabilities" error

Viewed 4437

I'm still fairly new to Selenium and am trying to create some minimally passing test cases (I guess you could call them the equivalent of a "hello world" program in a sense).

I tried to create an instance of the Firefox Driver like this:

var options = new FirefoxOptions()
{
    BrowserExecutableLocation = @"C:\Program Files(x86)\Mozilla Firefox\Firefox.exe",
    Profile = new FirefoxProfile(),
    LogLevel = FirefoxDriverLogLevel.Debug
};

firefoxDriver = new FirefoxDriver(options);

However, when I ran the test, I got the following error: Unable to find a matching set of capabilities. Several other answers I read on Stack Overflow and elsewhere suggested that the way to fix this is to explicitly specify the location of the binary file, like this:

firefoxDriver = new FirefoxDriver(new FirefoxBinary(@"C:\Program Files (x86)\Mozilla Firefox\firefox.exe"), new FirefoxProfile());

When I try that, it works, but I get the following compiler warning:

Warning CS0618 'FirefoxDriver.FirefoxDriver(FirefoxBinary, FirefoxProfile)' is obsolete: 'FirefoxDriver should not be constructed with a FirefoxBinary object. Use FirefoxOptions instead. This constructor will be removed in a future release.'

If the second version works, why doesn't the first version work as well, given that I clearly specified the BrowserExecutableLocation in FirefoxOptions? Is there a way to make something like the first way I tried work in order to avoid using the second, deprecated constructor?

FWIW, I'm using Firefox 52.2.0, and my NuGet packages are set as follows:

<packages>
  <package id="Selenium.Firefox.WebDriver" version="0.18.0" targetFramework="net452" />
  <package id="Selenium.WebDriver" version="3.4.0" targetFramework="net452" />
  <package id="Selenium.WebDriver.IEDriver" version="3.4.0" targetFramework="net452" />
</packages>
1 Answers
Related