Issues Configuring Selenium WebDriver to work in Visual Studio
In this post I'll show you how to configure Selenium 2.0 WebDriver to work with Visual Studio and Internet Explorer. (For some reason, I initially had a hard time getting this configured correctly.)
After much googling and trying different solutions from various places, I finally got Selenium work. Hopefully this post will help you avoid some of the issues I ran in to.
Download Selenium C# Client Drivers
- The first step is to download the C# dlls from Selenium's web site.
-
You'll also want to download the Internet Explorer Driver Server:

- Once you've downloaded the required Selenium files, extract the zips to a local drive on your computer
FYI - the Selenium Web Drivers work against IE 6,7,8 and 9 both 32-bit and 64-bit versions.
Configure Visual Studio to work with Selenium
- Launch Visual Studio and start a new project
-
Select 'Console Application' and name your project mySelenium

-
Next select Project>Add References from the tool bar and browser to the location where you extracted the Selenium dlls to. (Also be sure to select the correct version of .NET)

-
Select all the dlls and click ok

Time to Code!
Cool!! Now that we have the Selenium dlls referenced in our project, it's time to test the configuration by running a quick test.
At the top of your project code after the last 'using' namespace add the following Selenium namespaces:
using OpenQA.Selenium; using OpenQA.Selenium.IE; using OpenQA.Selenium.Support.UI;
Add the following code in your static void main section:
//!Make sure to add the path to where you extracting the IEDriverServer.exe:
IWebDriver driver = new InternetExplorerDriver(@"C:\Download\IEDriverServer"); driver.Navigate().GoToUrl("http://www.joecolantonio.com/HpSupport.html");Your code should look like this:

Run the test. joecolantonio.com should appear.
IE Developer Toolbar
If you are going to be scripting against IE you'll want to install the Internet Explorer Developer Toolbar. (Those familiar with QTP are aware that this is similar QTP's spy tool)
Using the IE Dev's Arrow feature allows you to spy on an element's attributes. You can then use those attributes in your Selenium code to help identify fields in you web application.

For example if we want to navigate to www.joecolantonio.com/HpSupport.html and select a value from the 'Select your tool & Version' we would point the IE Dev arrow to the field to see its attributes:

Now that we know what the Id is, we can use that information to help Selenium interact with it. For example:
myField = new driver.FindElement(By.Id("tools")); myField.SendKeys("QTP10");Run the test. It should start IE , navigate to http://www.joecolantonio/HPSupport.Html and select QTP10 from the Select your tool & version.
WTF's to look out for
If you getting the following error:
"InvalidOperationException was unhandled – unexpected error launching Internet Explorer. Protected Mode setting are not the same for all zones.
Enable Protected Mode must be set to the same value (enabled or disabled) for all zones"

In IE tools>Internet Options>Security tab, make sure all your zones are set to the same value:

If you are getting the following error:
"DriverServiceNotFoundException was unhandled: The file … \IEDriverServer.exe does not exist. The driver can be downloaded at"

Make sure that you downloaded the IEDriverServer.exe and also that you have the correct path specified in your code
IWebDriver driver = new InternetExplorerDriver(@"C:\YourPath\IEDriverServer"); //<-Add your path
Good Luck, and happy Selenium scripting!

{ 27 comments… read them below or add one }
Thanks a million mate. wasnt able to find any tutorial small and precise to get it working for chrome. this IE implementation did the job for me. thanks again mate. cheers.
Hardik Bhatt » Awesome – glad it helped!
This tutorial helps a lot and make me able to start scripting sucessfully.
Anurag Jain » Awesome – that’s what I like to hear!
hi joe thanks for the tutorial .actually i need your help ,i’m using selenium webdriver with visual studio c# chrome driver ,i added the selenium references and installed the chrome driver but i cannot add it as reference.
Engy » Hi are you getting an error message? I just verified that it worked for me. Did you verify that in your project>references that you have all the selenium dlls added? Also make sure that you added the name space namespace OpenQA.Selenium.Chrome. For the chrome driver you need to either have the path to it in your machines PATH environment variable or add it as an argument when you instantiate the Chrome Driver:
IWebDriver driver = new ChromeDriver(@”C:\pathToTheDriver\chromedriver\”);
Awesome tutorial.. thx m8
this got me up and running in no time.. would’ve taken me hours otherwise!
Cool – glad it helped. Let me know of any other Selenium issues you would like to see post on. Cheers~Joe
I was new to Selenium but this tutorial made me hit the ground running in 15 minutes!~
Good job Joe!
thanks
Jay
jay » Cool – thanks Jay! Glad it helped you.
Awesome tutorial. Super like
Is it the same step I have to follow for safari browser in windows 7 machine.
Saravanan Babhu » Thanks Saravanan – I have not tried against Safari yet.
Thanks so much Joe. Simple and it’s work.. Awesome!!
Now I can start the scripting with IE.
Thanks again..
Khairil Anuar » Thanks for the positive feedback – I really appreciate it! Glad it helped!
Hi Joe. Thanks for this page.
I am a QTP prof. I m completely new to Selenium. I am good with C#, but not that much with Java.
I find, that most of Selenium frameworks, like TestNG and ReportNG, are aligned to Java. But could not find as such for C#.
People say, NUnit and MBUnit aren’t that handy. Also, no reporting framework is available.
Do I need to learn Java all from scratch, or there are ways in C#? Please suggest. Thanks in advance !
Diptangshu Santra » Not sure what detail you need but we use nNunit without any issue. What do you need to do that nUnit is not handling? thanks~joe
Thanks for the info Joe. Worked like a charm.
Thanks a lot simple and perfect
shakkeer » Excellent!
please help me its not working as i have done all you guided …
issue is that when i am running the code iside visual studio it give an error that “visual studio can not start dbugging because the debug target is missing. please buid the project and retry, or set the outpput path and assembly name properties appropriately to point on correct location for target assembly” how to fix it??
sana » This is usually solved by changing the startup object in your project. This Microsoft thread has some suggestions for how to fix this error:
http://social.msdn.microsoft.com/Forums/en-US/vsdebug/thread/1a89d2df-0c57-4bb2-8c1a-b619e6cbb065/
Great sample.
Is there a way to record on IE using Selenium? ( the way you do on Firefox)
Thank you.
rony » Thanks Roy – Selenium IDE is a Firefox only plugin. Currently there is not something similar that can be used in IE.
Much appreciated
Great info, as usual!
I did something a little different, where I was creating it as a Test Project and going from there. I’m stuck on trying to write out my results to a notepad file though, but that’s another topic I suppose
Good starter tutorial, for people like me. Is there more tutorials on web testing using C#?
Thanks
sobi » Thanks! I will try to post more on web testing using C#. Does anyone else recommend any other resources?