Geckodriver with selenium 3.0 throws DriverServiceNotFoundException - c#

I need help to upgrade to geckodriver using C#. I downloaded geckodriver from here. Downloaded windows 64bit version as I'm on windows 10 64bit. Copied the driver to my project location.
Environment.SetEnvironmentVariable("webdriver.gecko.driver", #"C:\Git\AutomationTest\Drivers\geckodriver.exe");
FirefoxDriverService driverService = FirefoxDriverService.CreateDefaultService();
driverService.FirefoxBinaryPath = #"C:\Program Files (x86)\Mozilla Firefox\firefox.exe";
driverService.HideCommandPromptWindow = true;
driverService.SuppressInitialDiagnosticInformation = true;
driver = new FirefoxDriver(driverService, new FirefoxOptions(), TimeSpan.FromMilliseconds(600));
It threw error:
Initialization method UnitTestProject1.UnitTest1.Init threw exception. OpenQA.Selenium.DriverServiceNotFoundException: OpenQA.Selenium.DriverServiceNotFoundException: The geckodriver.exe file 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..
Result StackTrace:
at OpenQA.Selenium.DriverService.FindDriverServiceExecutable(String executableName, Uri downloadUrl)
at OpenQA.Selenium.Firefox.FirefoxDriverService.CreateDefaultService()
at OpenQA.Selenium.Firefox.FirefoxDriver..ctor(FirefoxOptions options)
at OpenQA.Selenium.Firefox.FirefoxDriver..ctor()
at UnitTestProject1.UnitTest1.Init()
Tried renaming it to 'Wires' but didn't work. Searched so many questions on SO, didn't find a solution with Selenium 3.0.
Added the path of the folder that has the driver to System variables path and tried using DesiredCapabilities.
DesiredCapabilities cap = DesiredCapabilities.Firefox();
cap.SetCapability("marionette", true);
var driver = new RemoteWebDriver(cap);
Using Selenium 3.0, FF 47.0.1, gecko v0.11.1
Can someone help me with this issue.
Thanks.

Try this:
FirefoxDriverService service = FirefoxDriverService.CreateDefaultService("C:\Git\AutomationTest\Drivers");
IWebDriver driver = new FirefoxDriver(service);

I updated Firefox to Version 49.0.2 and updated my selenium driver to 3.0.0 from nuget packages. Added Firefox path to the system path variables. That's it I didn't change anything else in my coding i.e, declaration of Firefox. After updating I'm having too many issues like wait and System.Net.Web exception. I need to fix some of my test cases but it works.

Related

How do i get selenuim to stop showing this error message?

I was trying to do a simple tester script because I wanted to get into it, but when I ran my first script, this happened. I tried installing gecko, but I have no idea how to install it, and all the tutorials didn't work for me. Any help would be much appreciated!
Using visual studio and c#
If you want to open firefox driver you need to set gecko driver by path.
//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");
new release https://github.com/mozilla/geckodriver/releases

org.openqa.selenium.WebDriverException: unknown error: cannot find Chrome binary [duplicate]

For compatibility reasons I prefer to use Chrome version 55.0.2883.75 with Chromedriver v. 2.26. I downloaded the older version of chrome from https://www.slimjet.com/chrome/google-chrome-old-version.php and Chromedriver 2.26 from https://chromedriver.storage.googleapis.com/index.html?path=2.26/.
I am using the following code to attempt to set my Chrome binary location:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
options = Options()
options.binary_location = "C:\\Program Files\\Chrome\\chrome64_55.0.2883.75\\chrome.exe"
driver = webdriver.Chrome('chromedriver.exe', chrome_options = options)
However, when I attempt to launch the WebDriver Python returns the following error:
WebDriverException: unknown error: cannot find Chrome binary
(Driver info: chromedriver=2.26.436362
(5476ec6bf7ccbada1734a0cdec7d570bb042aa30),platform=Windows NT 10.0.14393 x86_64)
I have tried searching through similar questions and answers but have not had any luck so far. Any help is greatly appreciated - thank you in advance!
This error message...
WebDriverException: unknown error: cannot find Chrome binary
...implies that the ChromeDriver was unable to find the Chrome binary in the default location for your system.
As per the ChromeDriver - Requirements:
The server expects you to have Chrome installed in the default location for each system:
OS
Expected Location of Chrome
Linux
/usr/bin/google-chrome1
Mac
/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome
Windows XP
%HOMEPATH%\Local Settings\Application Data\Google\Chrome\Application\chrome.exe
Windows Vista and newer
C:\Users%USERNAME%\AppData\Local\Google\Chrome\Application\chrome.exe
1 For Linux systems, the ChromeDriver expects /usr/bin/google-chrome to be a symlink to the actual Chrome binary.
Using a Chrome executable in a non-standard location
However you can also override the default Chrome binary location as follows:
To use Chrome version 55.x installed in non standard location through ChromeDriver v2.26 you can use the following code:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
options = Options()
options.binary_location = "C:\\Program Files\\Chrome\\chrome64_55.0.2883.75\\chrome.exe"
driver = webdriver.Chrome(chrome_options = options, executable_path=r'C:\path\to\chromedriver.exe')
driver.get('http://google.com/')
print("Chrome Browser Invoked")
driver.quit()
Related Docs
Reference
You can find a detailed discussion in:
Is Chrome installation needed or only chromedriver when using Selenium?
What happened to me is that I didn't have chrome, the main browser, installed.
Download the browser and it fixes this issue.
Using an old version of chrome driver with the latest Google Chrome locally gave me the same exception.
Just go to the ChromeDriver page and make sure you have the latest version.
I faced similar issue in MacOS. Even after setting binary path in chromeoptions, it didn't work. It got fixed after installing npm i chromedriver
It is also important to download Chrome from the actual website. I ran into the same problem, but I had downloaded Chrome from the Ubuntu software package manager. I uninstalled the package manager version and installed from the website, and the error resolved. Same issue could probably arise installing from other package managers.
Check https://sites.google.com/a/chromium.org/chromedriver/getting-started
You can specify the binary path in the constructor of the webdriver:
driver = webdriver.Chrome('/path/to/chromedriver') # Optional argument, if not specified will search path.
I did this to solve my problem
private WebDriver driver;
#Before
public void StartBrowser() {
System.setProperty("webdriver.chrome.driver", "C://opt//WebDriver//bin//chromedriver.exe");
driver = new ChromeDriver();
driver.get("https://www.saucedemo.com/");}
I have solved this problem by installing Google Chrome link and it solved problem automatically (I use Kali Linux) and be sure that it is installed to the "/usr/bin"(default it is downloaded to here).

Selenium C# FirefoxDriver not working for latest Selenium & Firefox

The Selenium is supposed to work with Firefox without any drivers out of the box, however I found that it is not the case with the latest Selenium & Firefox (install just days ago, Selenium 3 & Firefox ERS 52.5).
I'm following "Selenium C# and NUnit Pain Free Start Guide" as a total newbie, but found the simple Selenium C# NUnit test is not working for Firefox.
Here is my C# code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NUnit.Framework;
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.Chrome;
namespace NewSeleniumProject
{
[TestFixture]
public class MyFirstTest
{
IWebDriver driver;
[SetUp]
public void SetupTest()
{
// driver = new ChromeDriver();
driver = new FirefoxDriver();
//driver = new FirefoxDriver(new FirefoxBinary(#"C:\Program Files (x86)\Mozilla Firefox\Firefox.exe"), new FirefoxProfile(), TimeSpan.FromMinutes(10));
//var options = new FirefoxOptions();
//options.BrowserExecutableLocation = #"C:\Program Files (x86)\Mozilla Firefox\firefox.exe";
//driver = new FirefoxDriver(options);
}
[Test]
public void myFirstTest()
{
driver.Navigate().GoToUrl("http://www.swtestacademy.com");
Assert.AreEqual("SW Test Academy - Software Test Academy", driver.Title);
driver.Close();
driver.Quit();
}
}
}
And the following are my journeys to get it working.
First of all, the driver = new ChromeDriver() works for me without any hitch.
When I was using 32b Firefox ERS 52 with driver = new FirefoxDriver();, I'm getting the "Unable to determine the current version of FireFox using the registry" error, however none of the answers from Unable to determine the current version of FireFox after updated to 28.0 solves my problem. So I tried the "Try uninstalling Firefox and then re-installing it. That's what I would do" one.
Wit 64b Firefox ERS 52 (and driver = new FirefoxDriver();), I'm getting the "OpenQA.Selenium.WebDriverException : Cannot find Firefox binary in PATH or default install locations. Make sure Firefox is installed." error.
When using the var options = new FirefoxOptions(), for both 32b and 64b Firefox, I'm getting "OpenQA.Selenium.WebDriverException : The HTTP request to the remote WebDriver server for URL http://localhost:6985/session timed out after 60 seconds."
Again, the whole setup I'm following is from "Selenium C# and NUnit Pain Free Start Guide". What else I'm missing? Thx.
UPDATE:
This question is not about the error:
OpenQA.Selenium.DriverServiceNotFoundException : The geckodriver.exe file does not exist in the current directory or in a directory on the PATH environment variable.
which I've fixed by downloading the driver from https://github.com/mozilla/geckodriver/releases.
Make sure versions match first. Then try this way of doing for Firefox browser. I faced same challenges before but this way of calling Firefox solved the issue. Hope it might help
var binary = new FirefoxBinary(#"----Firefox.exe Local Path------");
var profile = new FirefoxProfile();
FirefoxDriverService service = FirefoxDriverService.CreateDefaultService(#"--GeckoDriver Path-----");
service.FirefoxBinaryPath = #"----Firefox.exe Local Path------";
driverInstance = new FirefoxDriver(service);
So yes, you will need to Dl the driver and place that in your bin folder of your application and pass the path location of the .exe to the driver service using the options() with {}.
I have the same thing, however there is a difference between the two. Firefox is installed in the 64 bit folder and chrome is located in the 32 bit folder (x86) Program Files and i believe this is where there issue lies in the Selenium only looks at the 32 bit folders for the applications .exe.
I ran into the same issue when i started using any other driver apart from edge.
another issue that you may run into with the new gecko driver is that firefox will not open on the requested URL. Note that this was in VB. Should be the same though. I may just run a test.

geckodriver.exe not in current directory or path variable, Selenium 2.53.1 + Firefox 48 + Selenium 3 Beta

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.
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
Install the Selenium.Firefox.Webdriver NuGet package.
This will copy geckodriver.exe to the bin folder.
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
Check out #juver-malpartida 's Answer
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.
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.
Add into Environment Path Yours drivers directory.
VisualStudio install Selenium using NuGet package manager in console mode or how would u like.
PM> Install-Package Selenium.WebDriver
restart VS.
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.
I would try this:
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.
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();
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.
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
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
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

c# Selenium 2.53 moving to marionette driver after firefox upgrade to 47

I am trying to move into the upgraded firefox web browser automation using selenium. It seems that selenium needs marionette driver to continue working. I followed the instructions set by the devs,
downloaded the driver
renamed it to wires.exe
The following code didnt manage to properly set the PATH to a custom path.
System.Environment.SetEnvironmentVariable("webdriver.gecko.driver", "#C:\DOWNLOADS\wires.exe")
so i added wires.exe to the debug\bin folder and then wires.exe worked properly but i got the following error
System.InvalidOperationException was caught Message=entity not found Source=WebDriver
this is the code i use to start webdriver
FirefoxOptions option1 = new FirefoxOptions();
option1.IsMarionette = true;
option1.AddAdditionalCapability("marionette", true);
driver = new FirefoxDriver(option1);
I too got the "Entity Not Found" error using FirefoxDriver(new FirefoxOptions()). It appears to be looking for firefox.exe in C:\Program Files (x86)\Nightly and not finding it. I found this working :
FirefoxDriverService service = FirefoxDriverService.CreateDefaultService();
service.FirefoxBinaryPath = #"C:\Program Files (x86)\Mozilla Firefox\firefox.exe";
IWebDriver driver = new FirefoxDriver(service);
I try with this and it's working:
Install FirefoxDevEdition
Download geckodriver.exe
FirefoxDriverService service = FirefoxDriverService.CreateDefaultService(#"C:\Users\jmalpartida\Downloads\geckodriver-v0.8.0-win32", "geckodriver.exe");
service.Port = 64444;
service.FirefoxBinaryPath = #"C:\Program Files (x86)\Firefox Developer Edition\firefox.exe";
IWebDriver driver = new FirefoxDriver(service);
First of all, you need to add the driver to your system path, not as an env variable.
Second, you need to set the flag in a desired capability, not a Firefox option. See: Marionette Webdriver
As such for remote webdriver:
DesiredCapabilities capabilities = DesiredCapabilities.Firefox();
capabilities.SetCapability("marionette", true);
var driver = new RemoteWebDriver(capabilities);
To add the webdriver to your windows path:
The easiest way is to open the start menu > search for environment > open edit the system environment variables > click on environment variables > search in the list for Path > click on edit > add ;C:\path\to\webdriver\location\wires.exe to the end and click save.
For your local (non-webdriver) tests you are right, you can run your webdriver using the following:
var driver = new FirefoxDriver(new FirefoxOptions());
You should not have to use
option1.IsMarionette = true;
option1.AddAdditionalCapability("marionette", true);
If you have set the driver path correctly in your path environment variable.

Categories