DriversRecommendedOutdated drivers can make a good PC feel brokenScan driver issues before chasing fixes manually.Scan NowOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run Scan×
Skip to content
World desk4 min

How to Set Up Selenium in Visual Studio with C#

Install Selenium.WebDriver with NuGet, run a first C# browser session in Visual Studio, and learn when Selenium Manager handles the driver setup for you.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To set up Selenium in Microsoft Visual Studio, add the Selenium.WebDriver NuGet package to a C#/.NET project, then create a ChromeDriver instance and run a small browser interaction. Selenium Manager handles browser-driver management by default, so downloading a driver separately is not a required first step.

What you need

  • Microsoft Visual Studio and a C#/.NET project.
  • A working .NET SDK for the project.
  • A browser you can run on the machine. The example below uses Chrome.

Selenium’s .NET examples use SDK-style projects. The Selenium .NET/C# downloads page listed version 4.49.0 as stable, released September 9, 2026; versions change, so check the current Selenium downloads page rather than treating that version as permanent guidance.

As an Amazon Associate I earn from qualifying purchases.

Install Selenium.WebDriver

Option 1: Visual Studio NuGet Package Manager

  1. In Visual Studio, open the solution and select the C# project that will run the automation.
  2. Open NuGet Package Manager for that project, search for Selenium.WebDriver, and install the package.
  3. Confirm the package appears as a dependency of the intended project before building.

Visual Studio labels can vary by version; the important point is to add the package to the project, not merely to the solution.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Option 2: .NET CLI

Open a terminal in the directory containing the project file and run:

dotnet add package Selenium.WebDriver

This adds a package reference to that project. Selenium also documents the equivalent project-file entry:

<PackageReference Include="Selenium.WebDriver" Version="4.49.0" />

Use the current package version shown by NuGet or Selenium’s download page when creating a new project; the version above reflects the Selenium downloads listing on September 9, 2026.

Run a first browser session

Create a C# file in the project and use this minimal interaction, based on Selenium’s official sample web form:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;

var driver = new ChromeDriver();

try
{
    driver.Navigate().GoToUrl("https://www.selenium.dev/selenium/web/web-form.html");

    var title = driver.Title;
    Console.WriteLine($"Page title: {title}");

    var textBox = driver.FindElement(By.Name("my-text"));
    textBox.SendKeys("Selenium in Visual Studio");

    driver.FindElement(By.TagName("button")).Click();

    var message = driver.FindElement(By.Id("message")).Text;
    Console.WriteLine($"Result: {message}");
}
finally
{
    driver.Quit();
}

The example opens Selenium’s demonstration form, enters text, clicks its button, and prints the returned message. Run the project from Visual Studio as you would any other console application. If you prefer, use the terminal in the project directory with dotnet run.

The try/finally ensures the browser session is asked to close even if an operation throws an exception. For a short-lived program, call Quit() once when the session is finished; avoid leaving browser processes running between repeated runs.

How browser and driver setup works

Selenium says its bindings use Selenium Manager by default for automated browser and driver management. The project overview describes it as “a command-line tool implemented in Rust that provides automated driver and browser management for Selenium.” In a normal first run, start with new ChromeDriver() rather than assuming you must manually download and configure a driver executable.

Manual setup may still be needed in constrained environments or when your team deliberately manages browser and driver versions itself. Selenium’s overview establishes the default manager behavior, but exact remediation depends on the machine, browser, network policy, and error message.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Choose between a script and a test project

One-off automation or a smoke test

A console application is sufficient to prove that Selenium can start a browser, navigate, and interact with a page. It does not require a test framework just to run a few steps.

A growing automated test suite

As checks multiply, put them in a test project and use a .NET test runner/framework to organize test cases, assertions, and setup and teardown. Selenium’s organizing guide describes runners as useful for advanced test organization and includes .NET examples, while noting that portions of the guide are incomplete. It does not make a particular framework mandatory for every Selenium user.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Troubleshooting the first run

  • Visual Studio cannot resolve OpenQA.Selenium. Check that Selenium.WebDriver was installed in the project containing the source file, then restore NuGet packages and rebuild.
  • The package command reports no project. Run dotnet add package Selenium.WebDriver from the directory containing the intended .csproj, or specify the project path.
  • Chrome does not start. Confirm Chrome is installed and can launch for the current user. Read the full exception; check machine permissions and whether network restrictions prevent Selenium Manager from doing its work.
  • The browser opens and immediately closes. Ensure the program has not exited and reached its finally block; when debugging, set a breakpoint before Quit() or inspect the exception that occurred first.
  • An element lookup fails. Confirm the target page loaded and that the locator matches the current page. A missing element can reflect a changed page, timing, or an incorrect selector rather than an installation problem.
  • The test passes locally but not in another environment. Compare installed browser availability, user permissions, network policy, and the exact Selenium exception before resorting to a manually pinned driver.

Or skip the browser setup

If the job is simply to capture a webpage rather than interact with it, ScreenshotNeo offers a one-request screenshot API and an MCP server for AI agents. Its clean-shot workflow accepts cookie or consent banners and removes more than 60 known consent platforms, newsletter popups, and chat widgets before capture; each step can be disabled. Bot checks/CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, with response headers reporting the page verdict and billing status. AI agents can use its MCP server tools, including take_screenshot, get_page_info, and capture_pdf.

cURL example (see the ScreenshotNeo API documentation):

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

ScreenshotNeo also has Python and Node.js examples in its documentation. Its free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000. Sign up for ScreenshotNeo’s free plan.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.