简体   繁体   中英

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.

嗨,解决了吗,你能把解决方案的链接发给我吗

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM