Selenium Automation Using C# - Part One

Setup required
  1. Visual Studio 2013+
  2. Internet for downloading the packages from NuGet packages.
Required Knowledge
  1. Basic C# Scripting knowledge 
  2. Basic HTML (for finding elements) 
Introduction

In this blog, we are going to automate a website using C# Selenium. It is the first step of automation. In this below topic, we are using Selenium, Chrome driver, and C# for scripting.

Steps to follow

Below are some of the images to start the automation.
  1. Open Visual Studio 2013+
  2. Click File >> Create a New project

    C#

  3. Click on Visual C# for choosing the language

    C#

  4. Click on "Test" for creating a test project.
  5. Select Unit Test Project Template. Create the project with a suitable name

    C#

  6. Open your project and click on Tools on topbar of Visual Studio.
  7. Click on NuGet Package Manager.
  8. Click on Manage NuGet Package for the solution.

    C#

  9. Search Selenium On Browse content of NuGet UI.

    Install Selenium.webDriver to your solutions,

    C#

  10. Search with Selenium.Chrome.WebDriver on Browser UI,

    Install Selenium.Chrome.WebDriver,

    C#

  11. Now, all setup is covered for our topics. Now we will go to the coding part.

    Now, go to the path of your Project folder and go to packages.

    1. Go to the driver folder
    2. Copy the Path of the driver under where chromedriver.exe is available. This will be available after the installation of the above packages into our solution.

      C#

  12. Go to your project and the open your UnitTest1.cs (Default)

    Paste the below code.
    1. [TestClass]  
    2. public class UnitTest1  
    3.    {  
    4.    [TestMethod]  
    5.    public void TestMethod1()  
    6.    {  
    7.       //Path of chromedriver.exe:  
    8.       IWebDriver driver = new ChromeDriver(@"C:\Users\Suman\FirstSeleniumDemo\packages\Selenium.Chrome.Web      Driver.2.40\driver"); //<-Add your path  
    9.       driver.Navigate().GoToUrl(@"https://www.c-sharpcorner.com/");  
    10.    }  
    11. }  
Now, run the test case.

You can open a website using Selenium Chrome driver using C# note.

Thanks a lot.