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
Conclusion: > Selenium WebDriver supports various programming languages like Java, Python, C#, Ruby, Perl, PHP, JavaScript, R, Objective-C and Haskell.
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.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With