Introduction To Selenium Webdriver With C# In Visual Studio 2015

What is Selenium Webdriver?

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

For details please go through the URL.

The use of Selenium Webdriver is to 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 applications 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 an infrastructure setup.

Steps to Set Infrastructure

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

Step 1. Open Visual Studio.

Step 2. Create a New Project.

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

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

Test project

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

Nuget Packages

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

Then you can see the following screen:

Manage Nuget Packages

Then follow the steps as in the following image.

  1. Search Selenium webdriver.
  2. Select Selenium. web driver
  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 the Selenium web driver in our C# application.

Code

Now we go step by step: Add the below references.

using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Firefox;

The above references can provide all classes and properties required to integrate the Selenium web drivers.

One more important thing is that download Chrome Driver on your local machine

Please download it from the URL.

In this way, you need to download Webdriver as per your expected browser.

Now we will run the test cases

Run test

Selenium

Now you can see the Chrome and Firefox browsers opened by 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. For the chrome browser, we do have ChromeDriver, for the Firefox browser we do have FirefoxDriver, and so on.

All these driver classes are derived from the RemoteDriver class.

The syntax to create an object of FirefoxDriver is.

By class

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


Similar Articles