简体   繁体   中英

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");

    }
}

}

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");

Figured it Out Guys.

It turns out 3.8.0 is only supported in C# , not 3.9 which nuget automatically installs as the WebDriver . All is working now, you don't even have to specify driverservice and point it to the path as it picks it up automatically.

Install Selenium.WebDriver.GeckoDriver via nuget package. (1) Right click project and select manage nuget package )

在此处输入图片说明

After installation your references in the project look like

在此处输入图片说明

After this you will not get the error

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM