Reputation: 65
Straight out of the box I can't get selenium grid to work. I have selenium server 3.4.0 and the following code produces the error shown
Error received
An unhandled exception of type 'System.InvalidOperationException' occurred in WebDriver.dll
Additional information: The path to the driver executable must be set by the
webdriver.gecko.driver system property; for more information, see
https://github.com/mozilla/geckodriver. The latest version can be downloaded
from https://github.com/mozilla/geckodriver/releases
Simple code
using System;
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.Remote;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
var url = new Uri("http://10.6.122.49:5555/wd/hub");
var options = new FirefoxOptions();
options.SetPreference("webdriver.gecko.driver", @"D:\geckodriver.exe");
var driver = new RemoteWebDriver(url, options.ToCapabilities());
driver.Navigate().GoToUrl("http://www.google.com");
}
}
}
Update
Upvotes: 1
Views: 6718
Reputation: 9115
in C#
Environment.SetEnvironmentVariable("webdriver.gecko.driver", @"C:\full\path\to\geckodriver.exe");
Upvotes: 0
Reputation: 69
I have explained here with clear example, make your changes accordingly
NOTE: Make sure of following this before starting.
You can download Geckodriver from this location https://github.com/mozilla/geckodriver/releases
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using OpenQA.Selenium;
using OpenQA.Selenium.Support;
using OpenQA.Selenium.Support.UI;
using NUnit.Framework;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.Chrome;
namespace ClassLibrary2
{
public class Class1
{
FirefoxDriverService service = FirefoxDriverService.CreateDefaultService(@"D:\dev1"); // location of the geckodriver.exe file
[Test]
public void GeckoDriverImplementation()
{
IWebDriver driver = new FirefoxDriver(service);
driver.Navigate().GoToUrl("https://google.com/");
}
}
}
Upvotes: 3
Reputation: 2267
Add an environment variable with the name : webdriver.gecko.driver and value =D:\geckodriver.exe under the system variables. and you can safely remove
options.SetPreference("webdriver.gecko.driver", @"D:\geckodriver.exe");
Hope this helps
Upvotes: 0