Cant define Selenium chrome driver path - c#

I write automation system and perfectly works in localhost, but when i try to publish it and upload to server. I got this error;
unknown error: cannot find Chrome binary
(Driver info: chromedriver=2.9.248315,platform=Windows NT 6.1 SP1 x86_64)
And I am 1 billion sure of this path, here is my code
var outPutDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase);
var options = new ChromeOptions();
var driverPath = Path.Combine(outPutDirectory, "ChromeDriverInThisFolder\\");
string driver_path = new Uri(driverPath).LocalPath;
driver = new ChromeDriver(driver_path, options);
My server is windows Windows NT 6.1 SP1 x86_64
2008 R2 Enterprise 64 bit

You can use the "standard location" of chrome, this way:
var options = new ChromeOptions();
// all of your 'options.AddArgument(...);' here
driver = new ChromeDriver(options); //This will look for chrome in the default directory
If you need to pass a chrome binary in a different directory you can use this way:
var options = new ChromeOptions();
// all of your 'options.AddArgument(...);' here
options.setBinary("pathToYourOtherBinary"); //This is for CHROME binary, not ChromeDriver binary
driver = new ChromeDriver(options);
After some research, here and here, I'm tempted to say that you don't have ChromeDriver on your server.
It should be somewhere on your AppData like this:
Windows XP %HOMEPATH%\Local Settings\Application Data\Google\Chrome\Application\chrome.exe
Windows Vista C:\Users\%USERNAME%\AppData\Local\Google\Chrome\Application\chrome.exe
Donwload ChromeDriver from here and install it on your server. Than the first option (whithout the path) will work.

Related

Unable to start chrome process in .NET C# application

I am getting error on Selenium and unable to start chrome process. I am using Google Chrome Version 96.0.4664.45 (64-bit) and Selenium Web Driver 3.141.0
ChromeOptions chromeOptions = new ChromeOptions
{
BinaryLocation = "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe"
};
chromeOptions.AddArgument("incognito");
using (ChromeDriver window = new ChromeDriver(chromeOptions))
{
try
{
log.Debug("Chrome window instantiated");
Did you install chromedriver too? If you haven't already: https://chromedriver.chromium.org/downloads

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

Geckodriver with selenium 3.0 throws DriverServiceNotFoundException

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.

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.

Browser extension testing with selenium c# in Saucelabs

Is it possible to test browser extensions with selenium c# in Saucelab. If so how and where to place the latest extension package in saucelab VM so that selenium launches the browser with the extension.
For Firefox and chrome it is possible by providing capabilities or profile. For Example in case of firefox:
File file = new File("firebug-1.8.1.xpi");
FirefoxProfile firefoxProfile = new FirefoxProfile();
firefoxProfile.addExtension(file);
firefoxProfile.setPreference("extensions.firebug.currentVersion", "1.8.1"); // Avoid startup screen
WebDriver driver = new FirefoxDriver(firefoxProfile);

Categories