32

Seen a lot of questions regarding Selenium 2.53.1 and Firefox 47.0.1, but none in regards to the Selenium 3 Beta release. I am attempting to use the new gecko/marionette Firefox webdrivers, but even though I have the driver location in; my environment path, Firefox install folder in programs, and give the drive location in the system environment, it will still not work correctly.

Error:

The geckodriver.exe does not exist in the current directory or in a directory on the PATH environment variable. The driver can be downloaded at https://github.com/mozilla/geckodriver/releases.

Using:

  • Selenium 2.53.1 server
  • Firefox 48
  • Selenium 3 Beta DLLs
  • Window 10

Example Code 1

    using OpenQA.Selenium.Firefox;

    public static class FirefoxInitialise
    {
         public static IWebDriver Driver {get; set;}

         Driver = new FirefoxDriver();
    }

Also attempted the below:

    using OpenQA.Selenium.Firefox;

    public static class FirefoxInitialise
    {
         public static IWebDriver Driver {get; set;}

         FirefoxDriverServices service = FirefoxDriverService.CreateDefaultService();
         service.FirefoxBinaryPath = @"C:\Program Files\Mozilla Firefox\firefox.exe";
         FirefoxOptions options = new FirefoxOptions();
         TimeSpan time = TimeSpan.FromSeconds(10);
         Driver = new FirefoxDriver(service, options, time);
    }

Any help or insight as to why the code still won't detect this driver would be greatly appreciated it.

SeanS
  • 418
  • 1
  • 6
  • 14
  • This may not be working at all for Windows according to [the comment by naveenkumar1](https://github.com/SeleniumHQ/selenium/issues/2600) on the GitHub for Selenium... – SeanS Aug 18 '16 at 10:54
  • Have a look at this post regarding C# - http://stackoverflow.com/questions/37761080/c-sharp-selenium-2-53-moving-to-marionette-driver-after-firefox-upgrade-to-47 – Grasshopper Aug 18 '16 at 11:09
  • Yeah, I've had a look through most of the C# ones, but they are all using the older 2.53 versions of the DLLs. The Selenium 3 beta ones are using geckodriver as standard instead of wires.exe now. I might try added geckodriver.exe to the bin/debug folder and see what happens... – SeanS Aug 18 '16 at 11:13
  • Possible duplicate of [Fail to Launch Mozilla with selenium](http://stackoverflow.com/questions/38676719/fail-to-launch-mozilla-with-selenium) – Saurabh Gaur Aug 18 '16 at 11:45
  • Not a duplication as those steps for solving on .NET have been tried and failed, as well as the geckodriver location added to PATH environment – SeanS Aug 19 '16 at 07:20
  • @SeanS Did you manage to solve the problem. I'm struggling to make it work. Can you help me if you find a solution to it. – Sudeepthi Oct 27 '16 at 08:45
  • @Sudeepthi I reverted back to the previous drivers before, I'm now currently onto another project in my company. I'm unsure if the answers below may work, but it might be best to try them. – SeanS Dec 05 '16 at 11:22
  • @SeanS I did solve my problem by adding the system path quite a while ago but didn't update here. I'm having some issues with my test cases but I'm able to run them. Thanks for tagging me. – Sudeepthi Dec 05 '16 at 13:10
  • var profile = new FirefoxProfile(); profile.AcceptUntrustedCertificates = true; profile.AssumeUntrustedCertificateIssuer = true; // driver = new FirefoxDriver(); driver = new FirefoxDriver(new FirefoxBinary(@"C:\Program Files\Mozilla Firefox\Firefox.exe"), new FirefoxProfile(), TimeSpan.FromMinutes(10)); – A user Jan 23 '17 at 16:11
  • can you try the above? Also try to mention the path of GECKO driver in the code. than a system variable – A user Jan 23 '17 at 16:11

11 Answers11

32

Try to put the geckodriver.exe in your path: C:\Users\YourName\Documents\Visual Studio 2013\Projects\seleniump\seleniump\bin\Debug

you can find geckodriver.exe at this link:

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

Stef Heyenrath
  • 9,335
  • 12
  • 66
  • 121
vdus
  • 442
  • 4
  • 4
27

Install the Selenium.Firefox.Webdriver NuGet package.

This will copy geckodriver.exe to the bin folder.

Hans Vonn
  • 3,949
  • 3
  • 21
  • 15
  • 1
    Make sure to install it into the project your tests are in, not just where it is referenced. – deasa Oct 05 '17 at 18:22
  • 7
    I've always had to specify to the FirefoxDriver that the geckodriver.exe is in the current directory. This is the easiest way to do that: `driver = new FirefoxDriver(Environment.CurrentDirectory);` – carlin.scott Sep 24 '18 at 21:48
10

This solution may helps you fix problem: ( It did help me though)

public class TestResult {

    private IWebDriver driver;
    private StringBuilder verificationErrors;
    private string baseURL;
    private bool acceptNextAlert = true;

    [TestInitialize]
    public void SetupTest() {
        FirefoxDriverService service = FirefoxDriverService.CreateDefaultService(@"C:\geckodriver", "geckodriver.exe");
        service.Port = 64444;
        service.FirefoxBinaryPath = @"C:\Program Files (x86)\Firefox Developer Edition\firefox.exe";
        driver = new FirefoxDriver(service);
        baseURL = "http://localhost:49539";
        verificationErrors = new StringBuilder();
    }
}
REFERENCE
Community
  • 1
  • 1
Angus Wu
  • 134
  • 1
  • 3
  • 1
    This requires you to download geckoverdriv.exe (which wasn't enumerated) and place in an uncontrolled/unversioned area. Cleanest way while matching Visual Studio Style is to use Nuget. – ffejrekaburb Mar 04 '20 at 19:25
  • indeed, maybe it is a better solution on this day – Angus Wu Apr 28 '20 at 03:57
4

If u include the geckodriver.exe in your project and you copy it to your target directory when you compile, the webdriver works as it did in previous versions.

Chalmette
  • 41
  • 1
2

This is for who is the begginers ill write the short version in the below after this post :) The easiest way first you need to download all drivers what browser you use and extract all drivers into e.g. C:\Selenium\ there and go to VisualStudio and from here add Selenium packages shown in the pictures Click here in console write this code PM>Install-Package Selenium.WebDriver after that copy your drivers directory and from windows search tab type variables and select (Edit the system environment and variables) shown pic2 in this windows you will have advanced tab at the below click Environment Variables... here you have System variables section find PATH or Path Variable and edit it be careful don't delete it!! next click new - paste directory of drivers and click all windws ok button that's all. restart your VS programm and ckeck it. After this you don't have to add director path into your Constructor like

IWebDriver driver2 = new InternetExplorerDriver(@"C:\Selenium"); 

One more thing don't forget to import files.

using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.IE;

For more Advanced IT guys.

  1. Add into Environment Path Yours drivers directory.
  2. VisualStudio install Selenium using NuGet package manager in console mode or how would u like.

    PM> Install-Package Selenium.WebDriver

  3. restart VS.
Saeed
  • 134
  • 1
  • 6
2

In your project, click on Tools --> Nuget Package Manager --> Manage NuGet Packages for Solution... The in the open Window Browse Selenium.FireFox.WebDriver Select Project and your project Name and click on install.

This is the easer form to put the driver on your Selenium Project.

1

I would try this:

  1. First, make sure your C# project runs the same .NET framework version as the Client Driver's libraries (when you download them from Selenium HQ, you should see the framework version they're based on). I have 3.5 and 4.0 as of 9/15/2017, so I had to downgrade my C# project to .NET 4.0 to use the 4.0 Client Driver libraries.

  2. In your code, when creating the Firefox Driver Service, make sure you explicitly specify the path to where your geckodriver.exe is located. See how I've added a path parameter to your call to FirefoxDriverService.CreateDefaultService:

    using OpenQA.Selenium.Firefox;
    
    public static class FirefoxInitialise
    {
      private static IWebDriver Driver{get; set;}
      public static IWebDriver Init()
      {
       // I'm assuming your geckodriver.exe is located there:
       // @"C:\MyGeckoDriverExePath\geckodriver.exe"
       FirefoxDriverService service = FirefoxDriverService.CreateDefaultService(@"C:\MyGeckoDriverExePath\");
       service.FirefoxBinaryPath = @"C:\Program Files\Mozilla Firefox\firefox.exe"; // May not be necessary
       FirefoxOptions options = new FirefoxOptions();
       TimeSpan time = TimeSpan.FromSeconds(10);
       Driver = new FirefoxDriver(service, options, time);
       return Driver;
     }
    }
    

So you can use :

IWebDriver driver = FirefoxInitialise.Init();
Ali Besharati
  • 918
  • 12
  • 25
0

If you have the executable in path environment variable, it likely means that it doesn't have permission to access it. As a workaround, try to run Visual Studio as administrator.

Or you could move it to somewhere that it have permission. Eg:

var service = FirefoxDriverService.CreateDefaultService(@"D:\tmp\Binaries");
service.FirefoxBinaryPath = FirefoxBinary;

var options = new FirefoxOptions();
options.SetPreference("browser.private.browsing.autostart", true);

_driver = new FirefoxDriver(service, options, TimeSpan.FromSeconds(30));

There I put the binaries in D:\tmp\Binaries\ and specified it in the code to check the geckodriver there.

Syakur Rahman
  • 2,056
  • 32
  • 40
  • The code `service.FirefoxBinaryPath = FirefoxBinary;` doesn't compile. Perhaps you could provide more context to make your code runnable. – Manfred May 16 '18 at 03:27
  • @Manfred It is a path for you firefox binary. Eg: If you have firefox binary located at `D:\firefox\firefox.exe`, that should be what the value of `FirefoxBinary` is. – Syakur Rahman May 16 '18 at 22:00
0

I kept getting this error also & the only thing I could do to finally fix it (not sure if it's the best answer for everyone who has this issue) was I placed the geckodriver.exe in my main Library directory, then I opened webdriver.py:

/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/selenium/webdriver/firefox/webdriver.py

found the line where it says: executable_path="geckodriver", firefox_options=None,

and changed it to:

executable_path="/Library/geckodriver", firefox_options=None

Md Faisal
  • 2,931
  • 8
  • 29
  • 34
Milena Paz
  • 11
  • 2
0

I was having a Visual Studio 2017 issue where the build would fail because it was looking in a non existent directory for the geckodriver exec. I also had added it using nuget pack manager. What I found was in Visual Studio->Project->Properties->Build it works if you make the build independent of the architecture: Platform target is Any CPU & either leave the other check boxes (Prefer 32-bit, Allow unsafe code, Optimize code) all unchecked or just have Prefer 32-bit checked (which is the default on my system). btw:my Application was a .NET Framework 4.5.2 Console Application

0

This solution worked for me for VS2017. Just copied the geckodriver.exe to my project folder like this:

C:\Users\pedne\Desktop\C#\FirstSolution\FirstSolution\bin\Debug

PrashantMP
  • 11
  • 1