How to configure selenium 3.0, get the error "The file geckodriver.exe does not exist ..." in C #

Updated selenium in visual studio to 3.0 and firefox to 47.0, and now I get this error when I try to use local webdriver mode: The geckodriver.exe file does not exist in the current directory or in the directory in the PATH environment variable.

When I use remote mode (seleniumhub), it works fine even if it uses firefox version 45.0.

I tried looking for some examples, but did not find anything for C #, only for java and still could not get it to work.

my webdriver setup:

switch (ConfigurationManager.AppSettings["WebDriverMode"].ToLower()) { case "local": switch (ConfigurationManager.AppSettings["WebDriverBrowserCapabilities"].ToLower()) { case "firefox": driver = new AdvancedFirefoxDriver(); break; case "ie": driver = new AdvancedInternetExplorerDriver(); break; case "chrome": driver = new AdvancedChromeDriver(); break; default: throw new NotImplementedException(string.Format("WebDriverBrowserCapabilities of \"{0}\" is not implemented for {1} mode", ConfigurationManager.AppSettings["WebDriverBrowserCapabilities"].ToLower(), ConfigurationManager.AppSettings["WebDriverMode"].ToLower())); } break; case "remote": var huburl = new Uri(ConfigurationManager.AppSettings["SeleniumHubAddress"]); DesiredCapabilities capabilities; switch (ConfigurationManager.AppSettings["WebDriverBrowserCapabilities"].ToLower()) { case "firefox": capabilities = DesiredCapabilities.Firefox(); break; case "ie": capabilities = DesiredCapabilities.InternetExplorer(); break; case "chrome": capabilities = DesiredCapabilities.Chrome(); break; default: throw new NotImplementedException(string.Format("WebDriverBrowserCapabilities of \"{0}\" is not implemented for {1} mode", ConfigurationManager.AppSettings["WebDriverBrowserCapabilities"].ToLower(), ConfigurationManager.AppSettings["WebDriverMode"].ToLower())); } capabilities.IsJavaScriptEnabled = true; driver = new AdvancedRemoteWebDriver(huburl, capabilities); break; default: throw new NotImplementedException(); } 
+8
source share
3 answers

Starting with Selenium 3.0, you should use the geckodriver browser for Firefox.

download the latest version of geckodriver here https://github.com/mozilla/geckodriver/releases

You have two options:

  1. enter the path to geckodriver in the windows system variable PATH .
  2. Or, specify the geckodriver.exe program directory as follows.

System.Environment.SetEnvironmentVariable("webdriver.gecko.driver",@"/path/to/geckodriver.exe"

Note: A system reboot may be required if you set the PATH environment variable.

Starting with Firefox 47 (excluding it), Selenium uses geckodriver features by default. For versions 47 and earlier, you may need to disable this feature so that Selenium can use the built-in support for Firefox, as we worked with these versions.

JAVA version to achieve the same:

 DesiredCapabilities d = new DesiredCapabilities(); d.setCapability("marionette", false); // to disable marionette. WebDriver driver = new FirefoxDriver(d); 

References:

  1. How to set system properties in C #
  2. https://msdn.microsoft.com/en-us/library/z46c489x.aspx
  3. https://superuser.com/questions/317631/setting-path-in-windows-7-command-prompt
  4. fooobar.com/questions/1259916 / ...
+8
source

I had a similar problem with the Chrome driver for Selenium, I took a course on creating an automation infrastructure and installed the NuGet package on infrastructure links instead of installing it in tests. enter image description here

+1
source

You can download geckodriver from here: https://github.com/mozilla/geckodriver/releases , and then you just need to add the file directory to the FirefoxDriver constructor as follows:
new FirefoxDriver("geckoDriverDirectory")

0
source

Source: https://habr.com/ru/post/1259913/


All Articles