0

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.

  • First of all, the driver = new ChromeDriver() works for me without any hitch.
  • When I was using 32b Firefox ERS 52 with driver = new FirefoxDriver();, I'm getting the "Unable to determine the current version of FireFox using the registry" error, however none of the answers from Unable to determine the current version of FireFox after updated to 28.0 solves my problem. So I tried the "Try uninstalling Firefox and then re-installing it. That's what I would do" one.
  • Wit 64b Firefox ERS 52 (and driver = new FirefoxDriver();), I'm getting the "OpenQA.Selenium.WebDriverException : Cannot find Firefox binary in PATH or default install locations. Make sure Firefox is installed." error.
  • When using the var options = new FirefoxOptions(), for both 32b and 64b Firefox, I'm getting "OpenQA.Selenium.WebDriverException : The HTTP request to the remote WebDriver server for URL http://localhost:6985/session timed out after 60 seconds."

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.

xpt
  • 20,363
  • 37
  • 127
  • 216

2 Answers2

2

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);
  • Thanks Jain, so what are your current versions of FF, and Selenium.WebDriver (and `geckodriver` if applicable) that match each other? – xpt Feb 28 '18 at 20:19
  • It was FF 53.0 version, Geckodriver 0.19 or 0.19.1. My system was 32 bit. Once you find a match, best practice would be to stop automatic update of FF. Otherwise, you will keep on getting this type of mismatch errors. Update browser only after doing test in other system. – Jain Devassy Mar 02 '18 at 14:03
0

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.

Grant
  • 33
  • 8
  • "_new gecko driver is that firefox will not open on the requested URL_", yep, that's exactly what I'm experiencing, with my VC code. So I believe it is the same thing. As for placing the dlls and exes into the `bin` folder of the application, the Nuget Package Management has taken care of that, which I've confirmed. So that's not something I'm worrying about now. – xpt Jan 02 '18 at 16:27
  • After upgrading selenium standalone jar to 3.7.1, the issue is resolved. Can you try this. – Grant Jan 05 '18 at 16:05
  • Sorry @Grant I'm too new to the Selenium whole thing to try out what you said -- I use [Selenium.WebDriver](https://www.nuget.org/packages/Selenium.WebDriver) for my VC code, and you can see that there is no version 3.7.1 but only 3.7.0 listed there. I do see from http://selenium-release.storage.googleapis.com/index.html?path=3.7/ that there is a selenium standalone jar 3.7.1, but I just don't know how to apply to my situation, because I'm relying on nuget to mange things for me. BTW, _what's your FF version when issue is resolved_? Thx. – xpt Jan 05 '18 at 17:51