Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
like image 338
tinneko Avatar asked Aug 17 '16 20:08

tinneko


People also ask

Is C supported by Selenium?

Conclusion: > Selenium WebDriver supports various programming languages like Java, Python, C#, Ruby, Perl, PHP, JavaScript, R, Objective-C and Haskell.

Can Selenium be used with Visual Studio?

Selenium is the most popular end-to-end automation testing tool in existence. It supports the most popular programming languages – C#, Java, Python, JavaScript, and many more. To set up Selenium C# with Visual Studio, just follow the steps below: Install Visual Studio.

Can Selenium WebDriver integrate with C#?

In order to use Selenium WebDriver with C#, you need to install Visual Studio. NUnit is the Unit Testing framework supported by Visual Studio and Selenium webdriver. We need to install NUnit Framework and NUnit Test Adapter onto Visual Studio inorder to use it.

Which is better Selenium with java or C#?

When you start with Selenium I would say JAVA would be a better option for many reasons: There are a lot of opportunities for Selenium with Java is higher in the market as there are very fewer opportunities in C# with Selenium.


1 Answers

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

like image 78
donyd Avatar answered Sep 27 '22 22:09

donyd