What is Selenium Webdriver ?
WebDriver is a automating web application testing tool. This provide 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 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.
Step 3: Adding Selenium references or drivers in C# project.
- Firstly, open solution explorer.
- Then expand the project.
- Right click on references and select ‘Manage Nuget Packages’ option.
Then you can see the following screen:
Then follow steps as in the following image:
- Search Selenium webdriver.
- Select Selenium.webdriver
- Click install.
After successfully installing you can see the following screen.
And in references.
Now open the file UnitTest1.cs to start actual coding to integrate selenium webdriver in our C# application.
Now we go step by step:
Add 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 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
And now you can see the Chrome and FireFox browser opened with searching Selenium.
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:
- IWebDriver driverFF;
- driverFF = new FirefoxDriver();
By class -
This class can provide the browser data by name, id, ClassName, LinkText, TagName, PartialLinkText, XPath