Introduction To Selenium Webdriver With C# In Visual Studio 2015

What is Selenium Webdriver?


WebDriver is an automating web application testing tool. This provides APIs that easily integrate with any programming language such as C#, Java, Python.

For details please go through the url.

The use of Selenium Webdriver is to basically test any web application.

What is C#?


C# is a programming language of Microsoft that enables developers to build a variety of secure and robust application that run on the .NET Framework.

Why do we need to integrate Selenium Webdriver with C#?


We can easily integrate the API or drivers in our C# application and test the Web Application.

How to integrate Selenium Webdriver with C#?


Before going on actual integration one should have infrastructure setup.

Steps to setup infrastructure:

Create simple project to integrate Selenium webdriver with C# in Visual Studio.

Step 1: Open Visual Studio.

Step 2: Create New Project.

Select Test project from the right panel and then select Unit test Projects.

If you are unable to found the Test project, then select the online template option and search for the template.

Test project

Step 3: Adding Selenium references or drivers in C# project.

Nuget Packages

  1. Firstly, open solution explorer.
  2. Then expand the project.
  3. Right click on references and select ‘Manage Nuget Packages’ option.

Then you can see the following screen:

Manage Nuget Packages

Then follow steps as in the following image:

  1. Search Selenium webdriver.
  2. Select Selenium.webdriver
  3. Click install.

After successfully installing you can see the following screen.

nuget package

And in references.

references

Now open the file UnitTest1.cs to start actual coding to integrate selenium webdriver in our C# application.

code

Now we go step by step:

Add below references:
  1. using OpenQA.Selenium;  
  2. using OpenQA.Selenium.Chrome;  
  3. using OpenQA.Selenium.Firefox;  
The above references can provide all classes and properties required to integrate the selenium webdrivers.

One more important thing is that download chromedriver on your local machine

Please download it from the url.

By this way you need to download webdriver as per your expected browser.

Now we will run the test cases

run test

Selenium

And now you can see the Chrome and FireFox browser opened with searching Selenium.

Chrome and FireFox browser

Now we will get some details about the Selenium Classes, Commands, Events and Elements

WebDrivers -

We can have webdrivers as per the web browser. Like for chrome browser we do have ChromeDriver, for Firefox browser we do have FirefoxDriver and so on.

Actually all this driver classes are derived from RemoteDriver class.

The syntax to create object of FirefoxDriver is:
  1. IWebDriver driverFF;  
  2. driverFF = new FirefoxDriver();  
By class -

This class can provide the browser data by name, id, ClassName, LinkText, TagName, PartialLinkText, XPath.


Similar Articles