Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting Selenium to Work with Firefox Driver on C# Latest 3.9.0

I Cannot get Selenium to work with the Firefox Driver on c#. Chrome works perfectly but not Firefox.

Using:

  • Netframework 4.6.1
  • Latest version of selenium 3.9.0
  • Gecko-driver Downloaded from (manage Nuget packages) 0.19.1
  • Using the MSTest.TestAdapater which should work perfectly as it did with Chrome.

I have already set the path variable in Windows.

GeckoDriver is already installed in the Bin folder in sources.

The Firefoxdriverservice does not exist so cannot use that command.

The error im getting is "threw exception: System.ComponentModel.Win32Exception: The system cannot find the file specified"

using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
using System.Windows.Forms;

 namespace BeatRecaptcha
{
[TestClass]
public class UnitTest1
{
    [TestMethod]
    public void TestMethod1()
    {

        IWebDriver driver = new FirefoxDriver();
        driver.Manage().Window.Maximize();

        //Go to Google
        driver.Navigate().GoToUrl("www.google.co.uk");

    }
}

}

like image 487
icebreakerman Avatar asked Jan 29 '23 17:01

icebreakerman


1 Answers

Not sure if you recently upgraded to the latest version of selenium but since Selenium 3.0 you also need to download the geckodriver.exe from the below url as per your system configuration.

https://github.com/mozilla/geckodriver/releases

Then you can try something like this:

//Give the path of the geckodriver.exe    
FirefoxDriverService service = FirefoxDriverService.CreateDefaultService(@"C:\Users\abcd\Downloads\geckodriver-v0.13.0-win64","geckodriver.exe")

//Give the path of the Firefox Browser        
service.FirefoxBinaryPath = @"C:\Program Files (x86)\Mozilla Firefox\firefox.exe";

IWebDriver driver = new FirefoxDriver(service);
driver.Navigate().GoToUrl("https://www.google.com");
like image 178
so cal cheesehead Avatar answered Feb 06 '23 11:02

so cal cheesehead