3

I'm trying to run some unit tests using Selenium Webdriver and C#.Net for Firefox browser but I was unable to do it (Chrome and IE11 browsers are working smoothly).

Here is the info I gathered:

OS: Windows 10 Enterprise

Gecko driver version: geckodriver-v0.17.0-win32

Mozilla Firefox version: 54.0.1 (32-bit)

Environment Path variable already set under "C:\LEO\SELENIUM C#\Firefox"

Piece of Code:

using System;
using System.Text;
using System.Threading;
using NUnit.Framework;
using OpenQA.Selenium;
using OpenQA.Selenium.Support.UI;
using OpenQA.Selenium.Firefox;

[TestFixture]
public class UnitTest3
{
    private IWebDriver driver;
    private StringBuilder verificationErrors;
    private string baseURL;

    [SetUp]
    public void SetupTest()
    {
        FirefoxDriverService service = FirefoxDriverService.CreateDefaultService(@"C:\LEO\SELENIUM C#\Firefox");
        service.FirefoxBinaryPath = @"C:\Program Files (x86)\Mozilla Firefox\firefox.exe";
        driver = new FirefoxDriver(service);
        baseURL = "http://www.dow.com";
        verificationErrors = new StringBuilder();
    }
}

Error:

Message: OpenQA.Selenium.WebDriverException : Unable to find a matching set of capabilities.

TearDown : System.NullReferenceException : Object reference not set to an instance of an object.

StackTrace:

enter image description here I will appreciate all your help, thanks.

2 Answers 2

2

Simple solution:

  • use NuGet to download the Firefox driver into your project
  • Geckodriver.exe should now be available in your solution explorer (see screenshot)
  • Make sure you set the property to Copy if newer (or Copy always)
  • Then simply use the code IWebDriver driver = new FirefoxDriver();, because the driver file will always be copied to your bin folder you don't need to reference an explicit path

enter image description here

1

If the browser is not installed in the default location maybe it is good to specify the BrowserExecutableLocation.

 FirefoxOptions firefoxOptions = new FirefoxOptions();
 firefoxOptions.AcceptInsecureCertificates = true;
 firefoxOptions.BrowserExecutableLocation = @"C:\your\location\Mozilla Firefox\Firefox.exe";
 driver = new FirefoxDriver(firefoxOptions);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.