Automation Using Selenium in C# With Example
Last Updated :
28 Apr, 2025
Selenium is an open-source Web UI automation testing suite. It was developed by Jason Huggins in 2004 as an internal tool at Thought Works. It supports automation across different browsers, platforms, and programming languages which includes Java, Python, C#, etc. It can be easily be deployed on Windows, Linux, Solaris, and Macintosh Operating Systems. It also provides the support for different OS (Operating System) for mobile applications like iOS, windows mobile and android.
Selenium consists of drivers specific to each language. Selenium Web driver is mostly used with Java and C#. Test scripts can be coded in selenium in any of the supported programming languages and can be run directly in most of the modern web browsers which include Internet Explorer, Microsoft Edge, Mozilla Firefox, Google Chrome, Safari, etc.
Steps for Automation Using Selenium in C#
Selenium WebDriver is set up for C# in which test cases are made for testing. For this first, make a new project in C# in visual studio. For installing and setting up Visual Studio, you can read the article How to Install and Setup Visual Studio for C#?. We make this project with the name Selenium Automation, and make it as a C# application. Proceed the steps as follows:
Step 1: First download the Selenium Web Driver. For Downloading the WebDriver go to Tools option then select Nuget Package Manager and then Manage Nuget Packages for Solution.

Step 2: In the Search Bar on the top, search for Selenium. Select Selenium.WebDriver and check the Project checkbox, here it will be Selenium Automation and click on Install.

Step 3: After that, a dialogue box will open asking to accept the licenses. This will start the installation process and install the selenium WebDriver.


Once Visual Studio is finished with the successful installation of the Selenium WebDriver, it will show output in logs
Writing the First Selenium C# Test
After setting up the selenium on C#, its ready for working. In the following steps it is a guide to make the first test case. At the top of your project import two namespaces as following:
using OpenQA.Selenium;
using OpenQA.Selenium.ChromeDriver;
Download the Chrome driver from ChromeWebDriver according to the Chrome browser version. Unzip the file and copy the path of the file into the 'ChromeDriver' Constructor in the code written below. Add the following code in your static void Main section to test it. The final code look like:
csharp
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using System;
namespace Selenium_Automation
{
class Program
{
static void Main(string[] args)
{
IWebDriver driver = new ChromeDriver("Path to Chrome Driver");
// This will open up the URL
driver.Url = "https://www.geeksforgeeks.org/";
}
}
}
Output:


After the above procedure run the test case. Note that this code will not execute unless Chrome driver for the Selenium is not downloaded and unzipped on the system.
Similar Reads
Selenium with C# for Automated Browser Testing Selenium is used to automate the desktop browser testing. It comes up with many components and from them, the major one is the web driver. Web driver is used for writing the code in different programming languages which will target the web elements and then apply the operation on it. We can use C#,
7 min read
How to Automate TestNG in Selenium? TestNG is an open-source test automation framework for Java, designed to make the process of testing more efficient and effective. Standing for "Next Generation," TestNG offers advanced features like annotations, data-driven testing, and parallel execution. When combined with Selenium, it provides a
4 min read
How can we Find an Element using Selenium? Selenium is one of the most popular and powerful tools for automating web applications. Selenium is widely used for automating user interactions on a web application like clicking on a button, navigating to a web page, filling out web forms, and many more. But to interact with a web application we f
6 min read
How to Automate Click Using Selenium WebDriver? Selenium is one of the most popular and powerful tools for automating web applications. Selenium is widely used for automating user interactions like filling out forms, clicking on a button, navigating to a web page, and many more. One of the most common tasks while working with Selenium is clicking
5 min read
How to handle Action class in Selenium? Selenium can click buttons, type in text boxes, and eveÂn scroll through pages, all by itself! But what makes SeÂlenium awesome is a special feature calleÂd the Action class. The Action class lets SeÂlenium perform more compleÂx actions, like dragging and dropping items, or holding down a key and
4 min read
Gmail Login using Java Selenium Automating Gmail login using Selenium WebDriver and Java is a common task for beginners learning web automation. Itâs an excellent exercise to understand how Selenium interacts with web elements and handles user inputs. This article will guide you through the process of automating Gmail login, provi
4 min read
Pros and Cons of Selenium as an Automation Testing tool Selenium is a free, open-source test execution automation platform for web applications. It implements itself using a browser-specific driver that accepts and transmits commands to the browser. You can develop test scripts in a variety of computer languages, including Ruby, Java, NodeJS, PHP, Perl,
8 min read
Maximize window with selenium in C# Selenium is a popular automation tool used for controlling and automating web browsers. It provides a way for developers and testers to automate interactions with web applications. Mainly it is used to mimic how a user would interact with the application. Selenium comes up with one of the major comp
3 min read
Best Practices for Selenium Test Automation Selenium Test Automation is a cornerstone of modern web application testing. To ensure that your Selenium scripts are both effective and reliable, it's crucial to follow best practices that enhance test quality and maintainability. Implementing the right strategies can save time, reduce troubleshoot
6 min read
Use of AutoIt in Selenium WebDriver AutoIt is a scripting language used to automate the Windows GUI and general scripting tasks on the Windows platform. AutoIt can be used with Selenium WebDriver to handle scenarios where automation involves interactions with Windows-based GUI elements. This article focuses on discussing the use of Au
8 min read