Reputation: 22984
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.
driver = new ChromeDriver()
works for me without any hitch. 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. 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. 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.
Upvotes: 0
Views: 5299
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
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