Click here to Skip to main content
13,902,437 members
Click here to Skip to main content
Add your own
alternative version

Tagged as


19 bookmarked
Posted 6 Aug 2015
Licenced Ms-PL

Getting Started with WebDriver C# in 10 Minutes

, 7 Aug 2015
Rate this:
Please Sign up or sign in to vote.
Short tutorial on how to start using one of the world's best web automation frameworks - WebDriver. Exact steps to follow through code in C# and images.


WebDriver is a tool for automating testing web applications, and, in particular, to verify that they work as expected. It aims to provide a friendly API that’s easy to explore and understand, which will help make your tests easier to read and maintain. It’s not tied to any particular test framework so that it can be used equally well with MSTest, NUnit, TestNG, JUnit and so on. This “Getting Started” guide introduces you to WebDriver’s C# API and helps get you started becoming familiar with it.

Create Your First WebDriver Test Project

  1. Create New Test Project in Visual Studio.

  2. Install NuGet package manager and navigate to it.

  3. Search for Selenium and install the first item in the result list.

Code Examples In WebDriver

Create an instance of a driver.

IWebDriver driverOne = new FirefoxDriver();
IWebDriver driverTwo = new InternetExlorerDriver("C:\\PathToMyIeDriverBinaries\");

Only the FirefoxDriver can be created without parameters. For all other drivers, you need to point the location where the particular driver is downloaded.

?dditional steps are required to use Chrome Driver, Opera Driver, Android Driver and iPhone Driver.

Navigate to specific URL.

driverOne.Navigate().GoToUrl("<a href="" rel="noreferrer" style="display: inline !important; removed: help;"></a>");

Locating Elements with WebDriver


IWebElement element = driverOne.FindElement(By.Id("myUniqueId"));

By Class (Find more than one element on the page)

IList<IWebElement> elements = driverOne.FindElements(By.ClassName("green"));

By Tag Name

IWebElement frame = driverOne.FindElement(By.TagName("iframe"));

By Name

IWebElement cheese = driverOne.FindElement(By.Name("goran"));

By Link Text

IWebElement link = driverOne.FindElement(By.LinkText("best features"));

By XPath

IList<IWebElement> inputs = driverOne.FindElements(By.XPath("//input"));

By CSS Selector

IWebElement css = driverOne.FindElement(By.CssSelector("#green span.dairy.baged"));

Chaining Locators

Use a Chain of Locators to find a particular element.

IWebElement hardToFind = this.driverOne.FindElement

IWebElement Methods

IWebElement Properties

HTML Element Actions in WebDriver

Type Text into a field using Selenium WebDriver SendKeys() function.

IWebElement element = driverOne.FindElement(By.Name("search"));
element.SendKeys("Automate The Planet!");

Select Drop Down Value. First, you need to add NuGet Package to your project- Selenium.Support.

SelectElement selectElement = new SelectElement(driver.FindElement(By.XPath("/html/body/select")));

So Far in the 'Pragmatic Automation with WebDriver' Series


This article, along with any associated source code and files, is licensed under The Microsoft Public License (Ms-PL)


About the Author

Anton Angelov
CEO Automate The Planet
Bulgaria Bulgaria
Anton Angelov is an IT Consultant and Quality Assurance Architect at Innovative Lab. He is passionate about automation testing and designing test harness and tools, having the best industry development practices in mind. In addition, he is an active blogger and the founder of Automate The Planet. He strives to make the site one of the leading authorities in Automation Testing by presenting compelling articles, inspiring ardent discussions amongst the community. He is also one of the most-rated-answer authors of questions about Test Automation Frameworks (WebDriver) on Stack Overflow.

You may also be interested in...


Comments and Discussions

QuestionGood one to start with !!! Pin
K K Kodoth7-Aug-15 4:06
memberK K Kodoth7-Aug-15 4:06 
BugFormatting Pin
Florian Rappl6-Aug-15 23:56
professionalFlorian Rappl6-Aug-15 23:56 
GeneralRe: Formatting Pin
Anton Angelov7-Aug-15 2:10
memberAnton Angelov7-Aug-15 2:10 
GeneralRe: Formatting Pin
Florian Rappl7-Aug-15 3:33
professionalFlorian Rappl7-Aug-15 3:33 
GeneralRe: Formatting Pin
Anton Angelov7-Aug-15 3:34
memberAnton Angelov7-Aug-15 3:34 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web02 | 2.8.190306.1 | Last Updated 7 Aug 2015
Article Copyright 2015 by Anton Angelov
Everything else Copyright © CodeProject, 1999-2019
Layout: fixed | fluid