2

I'm having the same issue as this post linked, I'm currently re-reading the Selenium HQ documentation focusing on setting up the PATH environment. this is my code I want to run.

using System;
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
namespace ConsoleApp3
{
   class Program
   {
         static void Main(string[] args)
         {
             Console.WriteLine("Hello World!");
             IWebDriver driver = new FirefoxDriver();
             driver.Url = "http://www.google.com";
         }
   }
}

Installed Selenium Nuget Packages

I followed the steps above and still get this OpenQA.Selenium.DriverServiceNotFoundException

jnprogrammer
  • 153
  • 1
  • 3
  • 9

3 Answers3

1

I created a new Console App (.NET Framework) project in VS 2017, pasted in your code, and only installed Selenium.Firefox.WebDriver v0.19.1 and Selenium.WebDriver v3.8.0 using NuGet. I launched FF and made sure that it was fully updated, current version is 57.0.4 (64-bit).

Once all that was done, I built and ran the project and it worked just fine.

You have the Win64 FF driver installed. You are running Windows 64 bit?

If you don't require FF, I would switch to the Chrome driver and see if it works. Selenium.WebDriver.ChromeDriver v2.35.0 by jsakamoto. If you do use the Chrome driver, you will want to make sure that Chrome is up-to-date also before using. You will also want to replace the new FirefoxDriver(); portion with new ChromeDriver(); and add the proper using statement.

JeffC
  • 22,180
  • 5
  • 32
  • 55
  • I followed these steps exactly and I got the same result. I do have windows 8.1 64bit installed and VS 2017 installed. I have FF up to date. I get the same result with chrome. – jnprogrammer Jan 17 '18 at 05:01
1

Since you're using visual studio, just add the geckodriver.exe file to the solution, and from right-click -> properties, choose to "Copy always" the file to your output (when building the solution and run tests, this file will always exists with your compiled DLL).

After that, also deploy your file with the class attribute (add this above your BaseTest class, or [TestInitialize] like so:

[DeploymentItem("@*folder*\geckodriver.exe", "Drivers")]
[TestInitialize]
public void InitializeTest() {...}

OR

[DeploymentItem("@*folder*\geckodriver.exe", "Drivers")]
public class BaseTest {...}

Now that your driver executable gets deployed each time you run a test, you can find it here: AppDomain.CurrentDomain.BaseDirectory in the folder Drivers.

Then, just initialize your Driver like this using the constructor public FirefoxDriver(string geckoDriverDirectory); (You combine the base folder of your compile (either debug or run (they have different folders), with the folder the driver is in "Drivers" and search the geckodriver.exe in it.)

public FirefoxDriver(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Drivers"));

Note: The solution above is for when you're using selenium on unit testing. If you can't find the attribute DeploymentItem, the just use a static location for your driver (e.g.) "C:/" and call the contruction: public FirefoxDriver("C:/geckodriver.exe");

1

Alright I solved it. Thank you everyone for your help, Thodoris your method had shown me how to add the geckodriver.exe to the project. I realized I can pass the path as an argument into FirefoxDriver() with that I compiled and Firefox opened.

  var driver = new FirefoxDriver(@"C:\Users\jnprogrammer9\source\repos\ConsoleApp3\ConsoleApp3");

This link also helped me find the solution.

Also with testing I found that linking the both Chrome and gecko drivers to my project in VS2017 and installing only Selenium.WebDriver v3.8.0 using NuGet as you said JeffC. I was also able to get web browsers to open. Thank you both !!

jnprogrammer
  • 153
  • 1
  • 3
  • 9
  • That was going to be my next suggestion... make sure you clean out all other driver references. Once you install packages using only NuGet, everything gets a lot easier. No more hard coding paths, etc. – JeffC Jan 17 '18 at 19:04