xpt
xpt

Reputation: 22984

Selenium C# FirefoxDriver not working for latest Selenium & Firefox

The Selenium is supposed to work with Firefox without any drivers out of the box, however I found that it is not the case with the latest Selenium & Firefox (install just days ago, Selenium 3 & Firefox ERS 52.5).

I'm following "Selenium C# and NUnit Pain Free Start Guide" as a total newbie, but found the simple Selenium C# NUnit test is not working for Firefox.

Here is my C# code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using NUnit.Framework;
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.Chrome;

namespace NewSeleniumProject
{
    [TestFixture]
    public class MyFirstTest
    {
        IWebDriver driver;

        [SetUp]
        public void SetupTest()
        {
            // driver = new ChromeDriver();
            driver = new FirefoxDriver();

            //driver = new FirefoxDriver(new FirefoxBinary(@"C:\Program Files (x86)\Mozilla Firefox\Firefox.exe"), new FirefoxProfile(), TimeSpan.FromMinutes(10));

            //var options = new FirefoxOptions();
            //options.BrowserExecutableLocation = @"C:\Program Files (x86)\Mozilla Firefox\firefox.exe";
            //driver = new FirefoxDriver(options);

        }

        [Test]
        public void myFirstTest()
        {
            driver.Navigate().GoToUrl("http://www.swtestacademy.com");

            Assert.AreEqual("SW Test Academy - Software Test Academy", driver.Title);

            driver.Close();

            driver.Quit();
        }
    }
}

And the following are my journeys to get it working.

Again, the whole setup I'm following is from "Selenium C# and NUnit Pain Free Start Guide". What else I'm missing? Thx.

UPDATE:

This question is not about the error:

OpenQA.Selenium.DriverServiceNotFoundException : The geckodriver.exe file does not exist in the current directory or in a directory on the PATH environment variable. 

which I've fixed by downloading the driver from https://github.com/mozilla/geckodriver/releases.

Upvotes: 0

Views: 5299

Answers (2)

Jain Devassy
Jain Devassy

Reputation: 41

Make sure versions match first. Then try this way of doing for Firefox browser. I faced same challenges before but this way of calling Firefox solved the issue. Hope it might help

var binary = new FirefoxBinary(@"----Firefox.exe Local Path------");
var profile = new FirefoxProfile();
FirefoxDriverService service = FirefoxDriverService.CreateDefaultService(@"--GeckoDriver Path-----");
service.FirefoxBinaryPath = @"----Firefox.exe Local Path------";
driverInstance = new FirefoxDriver(service);

Upvotes: 3

Grant
Grant

Reputation: 33

So yes, you will need to Dl the driver and place that in your bin folder of your application and pass the path location of the .exe to the driver service using the options() with {}.

I have the same thing, however there is a difference between the two. Firefox is installed in the 64 bit folder and chrome is located in the 32 bit folder (x86) Program Files and i believe this is where there issue lies in the Selenium only looks at the 32 bit folders for the applications .exe.

I ran into the same issue when i started using any other driver apart from edge. another issue that you may run into with the new gecko driver is that firefox will not open on the requested URL. Note that this was in VB. Should be the same though. I may just run a test.

Upvotes: 0

Related Questions