Can't launch chrome driver in Selenium - c#

I was always able to launch chromedriver server locally but then I tried to do this remotely and since then I am unable to launch it. I reinstalled chrome as well the chrome driver but nothing seems to fix this. Even when I give the path of my driver it won't launch.
using OpenQA.Selenium;
using OpenQA.Selenium.Support;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.IE;
using OpenQA.Selenium.Chrome;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using OpenQA.Selenium.Safari;
using OpenQA.Selenium.Interactions;
namespace TestWebDriver
{
class Program
{
static void Main(string[] args)
{
var driver = new ChromeDriver(#"C:\Users\laurens.putseys\Documents\Visual Studio 2015\Projects\TestWebDriver\packages\Selenium.WebDriver.ChromeDriver.2.21.0.0\driver\");
driver.Url = "http://google.be";
Console.ReadLine();
driver.Quit();
}
}
}
The error I get is the following:
An unhandled exception of type 'System.InvalidOperationException' occurred in WebDriver.dll
Additional information: unknown error: chrome failed to start
(Driver info: chromedriver=2.21.371459 (36d3d07f660ff2bc1bf28a75d1cdabed0983e7c4),platform=Windows NT 6.1 SP1 x86_64)
It started after I tried this:
System.Environment.SetEnvironmentVariable("webdriver.chrome.driver",#"/path/to/where/you/ve/put/chromedriver.exe"
Now I cannot launch the local either. Launching IE and Firefox local work without any problems. Any ideas? Thanks in advance!

try downloading the driver and give its path to contractor - LINK
driver = new ChromeDriver(DRIVER_PATH);

By the version number (2.21.371459) you can tell that the ChromeDriver executable has been launched by your remote Selenium server. But the ChromeDriver was obviously unable to launch the Chrome browser. Is it installed on the server? Can you launch is manually? Can you watch the remote server on a screen and see what happens? Are there any error message boxes displayed by Chrome?
Maybe uninstalling and re-installing Chrome could help!

I had the same problem. I had the browser set to always run under the administrator.
So I started Visual Studio as an administrator and the problem was solved.

Related

Appium launching on real device but chrome hangs

I'm running Appium 1.6.1 on Windows 10, and I'm trying to automate Chrome on a real device (in this instance a Samsung Galaxy S7 running Android 7.0). I'm using C# and visual studio. My code looks like the below:
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium.Appium;
using OpenQA.Selenium;
using OpenQA.Selenium.Remote;
using OpenQA.Selenium.Appium.Android;
namespace MobileBrowserTesting{
[TestClass]
public class UnitTest1{
AppiumDriver<IWebElement> Driver;
[TestMethod]
public void TestMethod1(){
DesiredCapabilities caps = new DesiredCapabilities();
caps.SetCapability("deviceName", "hero2lteskt");
caps.SetCapability("udid", "ce11160b3889d43005"); //Give Device ID of your mobile phone
caps.SetCapability("browserName", "Chrome");
//Launch the Android driver
Driver = new AndroidDriver<IWebElement>(new Uri("http://127.0.0.3:4723/wd/hub"), caps);
Driver.Navigate().GoToUrl("http://www.google.com");
string url = Driver.Url;
bool viewable = Driver.FindElement(By.Id("q")).Displayed;
}
}
}
Chrome launches, however it simply sits at "data;" with a blank screen and doesn't progress to the website. The last step in the Appium view is:
[JSONWP Proxy] Proxying [POST /session] to [POST
http://127.0.0.1:8001/wd/hub/session] with body: {"desiredCapabilities":
{"chromeOptions":
{"androidPackage": "com.android.chrome","androidDeviceSerial":"ce11160b3889d43005"}}}
[HTTP] <-- POST /wd/hub/session - - ms - -
And visual studio times out with the error message:
Message: Test method MobileBrowserTesting.UnitTest1.TestMethod1 threw
exception:
OpenQA.Selenium.WebDriverException: The HTTP request to the remote WebDriver server for URL http://127.0.0.3:4723/wd/hub/session timed out after 60 seconds. ---> System.Net.WebException: The operation has timed out
After a while Appium times out with:
[W3C] Encountered internal error running command: Error: Failed to start
Chromedriver session: An unknown server-side error occurred while processing
the command. (Original error: unknown error: Device ce11160b3889d43005 is
already in use
Appium is launched in admin mode, with "Allow session override" ticked under Advanced.
The chromedriver being used is the latest one (2.39) and the version of chrome on the device is 66.0.3359.158 so it should be compatible.
Any ideas why it seems to hang/not interact with Chrome?
Cheers in advance

Headless Firefox in Selenium C#

I want to run firefox headless.
Not hide the browser window or open it in a virtual desktop, Firefox supports headless mode by using "-headless" flag.
Problem is I know how to do it in chrome but not in Firefox.
My code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
namespace MyApp {
public partial class Form1: Form {
public Form1() {
InitializeComponent();
}
private void StartBtn_Click(object sender, EventArgs e) {
IWebDriver driver;
FirefoxOptions options = new FirefoxOptions();
options.AddArguments("--headless");
driver = new FirefoxDriver(options);
}
}
}
My WinForm application only has a button with name StartBtn.
On clicking of the button Firefox should run headless, but it opens in a normal window.
Update
I updated firefox to 56.0.1
Now I get a different error:
An unhandled exception of type 'OpenQA.Selenium.WebDriverException'
occurred in WebDriver.dll
Additional information: Expected browser binary location, but unable
to find binary in default location, no 'moz:firefoxOptions.binary'
capability provided, and no binary flag set on the command line
Headless mode in Firefox is supported from version 56 on Windows and Mac OS. Ensure that you have the correct version installed.
https://developer.mozilla.org/en-US/Firefox/Headless_mode#Browser_support
With Firefox v56.0.1, Selenium.WebDriver v3.6.0 and geckodriver v0.19.0 (x64) this works correctly for me.
Regarding the error:
An unhandled exception of type 'OpenQA.Selenium.WebDriverException' occurred in WebDriver.dll
Ensure you're using the correct version of geckodriver. I suspect you're using the x32 build on an x64 machine, get the x64 build.
https://github.com/mozilla/geckodriver/releases

Selenium - Visual Studios- C# - All (chrome, firefox, and internet explorer) webdrivers unable to start driver service

I'm trying to set up Selenium for testing and none of my webdrivers seem to work. I have tried moving them around in the project folder and the only way I can get Visual Studios to locate them is with a #"path" statement.
The real problem is... Once Visual Studio locates the webdriver, the operation times out and I get the following exception:
An unhandled exception of type 'OpenQA.Selenium.WebDriverException' occurred in WebDriver.dll
Additional information: Cannot start the driver service on http://localhost:(random port number that changes every time)
I have tried restarting my computer and having the system administrator check the firewall and malware blocker logs, but neither seems to have helped (or they don't know the correct thing to look for).
I figure this is something super simple and I'm just missing it... Any help would be greatly appreciated.
Here is a copy of my code:
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.Support.UI;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.IE;
namespace SeleniumWork
{
class Program
{
static void Main(string[] args)
{
IWebDriver driver = new InternetExplorerDriver(#"C:\blahblahpathstring");
driver.Navigate().GoToUrl("http://www.google.com/");
IWebElement query = driver.FindElement(By.Name("q"));
query.SendKeys("Cheese");
query.Submit();
var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
wait.Until(d => d.Title.StartsWith("cheese", StringComparison.OrdinalIgnoreCase));
Console.WriteLine("Page title is: " + driver.Title);
}
}
}
Here is a copy of the debug output I receive:
A first chance exception of type 'System.Net.WebException' occurred in System.dll
A first chance exception of type 'System.Net.WebException' occurred in System.dll
A first chance exception of type 'System.Net.WebException' occurred in System.dll
A first chance exception of type 'System.Net.WebException' occurred in System.dll
A first chance exception of type 'OpenQA.Selenium.WebDriverException' occurred in WebDriver.dll
I have had the same problem on my work machine, but not on my personal machine. The only difference I could attribute between the two was that I was using VS 2015 at home and VS 2017 at work.
What fixed it was I used the NuGet Package Manager for the project and downloaded the Selenium.Firefox.WebDriver by jbaranda, which uses the new marionette based web driver rather than gecko driver.
With this installed I was able to get a firefox browser up and running without any extra configuration or options:
IWebDriver driver = new FirefoxDriver();
driver.Url = "www.google.com";
Whereas before it would throw the 'Cannot start the driver service...' exception you mentioned. There are NuGet packages for other browsers which I suggest for the particular one you're using, but the only one I didn't have that issue with was IE. Hope that helps
I had the same issue, and had had no idea how to fix it. In the end I found out that the Firewall blocked the traffic to loopback. The firewall installed on the machine is McAffe.
All I did was stopping the service which manages traffic scan.
Hope it will help you.
I've been hitting this consistently on IEDriverServer and rarely on FireFox.
Fixed it twice when it happened on FireFox - first time I updated the gecko driver, second time I restarted my PC. Something in the environment's going on, maybe the driver does not fully quit sometimes, so new instantiations are being blocked?
I think mostly beginners face this problem when they are running Selenium with C# for the first time.
As i also faced this situation. As highlighted in one of the answer and let me show with images
You have installed Selenium.webDriver but you have not installed Selenium.Firefox.WebDriver
Step 1 :- Go to Nugget Manager
Step 2 :- Select Selenium.Firefox.WebDriver and install it
Now run the program once again and that problem will go away.

InternetExlorerDriver cannot be found even after referencing all selenium DLLs

I'm trying to get started using Selenium by running some of the samples. I've seen others having trouble at run time getting the InternetExplorerDrive working, see How to instantiate InternetExplorerDriver with Selenium WebDriver using C#, but my problem is different. I get a compile time error that InternetExlorerDriver could not be found. I've installed all four "Official NuGet Packages: RC WebDriver WebDriverBackedSelenium Support" in my project.
I have the IEDriverServer.exe added to the project too but I'm not getting that far yet.
What reference am I missing?
using System;
using System.Threading;
using OpenQA.Selenium;
using OpenQA.Selenium.Support.UI;
namespace SeleniumTest
{
class Program
{
static void Main(string[] args)
{
// Create a new instance of the Firefox driver.
// Notice that the remainder of the code relies on the interface,
// not the implementation.
// Further note that other drivers (InternetExplorerDriver,
// ChromeDriver, etc.) will require further configuration
// before this example will work. See the wiki pages for the
// individual drivers at http://code.google.com/p/selenium/wiki
// for further information.
IWebDriver driver = new InternetExlorerDriver(); //missing reference error here
Compile time error:
Error 1 The type or namespace name 'InternetExlorerDriver' could not be found (are you missing a using directive or an assembly reference?) c:\users\chadd\documents\visual studio 2013\Projects\SeleniumWebDr\SeleniumTest\Program.cs 22 37 SeleniumTest
I notice that in your code, you don't have a using statement for the IE driver's namespace. Add the following line to your source code:
using OpenQA.Selenium.IE;
See if that doesn't resolve the issue.
Additionally, in your code, you're attempting to instantiate a class named InternetExlorerDriver. You're missing a p there. InternetExplorerDriver is what you want.
Incidentally, Visual Studio should provide you with tooltip support to correct this issue.
You have to download the IE Explorer driver from selenium hq site in order to invoke the Internet explorer browser as selenium only supports firefox as its default browser.
Please find below the link: http://www.seleniumhq.org/download/
download the 32 bit or 64 bit internet explorer driver server and just add the below setting in your script:
System.setProperty("webdriver.ie.driver",
System.getProperty("user.dir") + "\\IEDriverServer.exe");
Webdriver driver = new InternetExplorerDriver();
assuming you have kept the exe file in the same project folder. hope this helps !!

Chrome Driver issues in C# selenium

I wrote my first selenium script and it worked. here is the code below
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
namespace test1Sel
{
class Program
{
static void Main(string[] args)
{
IWebDriver driver = new ChromeDriver(#"C:\ChromeDriver");
If i try and write a new script however i get an error on the driver saying Invalid argument has been supplied. I am using Visual Studio 2013 Pro. I am not sure why the line worked the first time but will not work in any other script. i have installed both selenium packages in the first script and in any other test script i have tried. any ideas would be great!
Try to replace Chrome driver into the bin folder (solution\project\bin\debug), and use constructor without path (without arguments).
IWebDriver driver = new ChromeDriver();

Categories

Resources