Install Selenium WebDriver for .NET Core

Run the following command to install the Selenium WebDriver NuGet package:

dotnet add package Selenium.WebDriver

You’ll also need to download the WebDriver executable for the browser you intend to use. For example, if you are planning to use Chrome, you’ll need to download ChromeDriver.

You can download it from the official site and place the executable in a directory that is in your system’s PATH, or specify its location in your code.

Write Your Test Code

Now you can write your Selenium test code in the Program.cs file. Here’s a simple example to open Google’s homepage:

using System;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;

namespace MySeleniumApp
    class Program
        static void Main(string[] args)
            // Initialize the Chrome Driver
            using (IWebDriver driver = new ChromeDriver())
                // Navigate to Google

                // Close the driver