Setup required
- Visual Studio 2013+
- Internet for downloading the packages from NuGet packages.
Required Knowledge
- Basic C# Scripting knowledge
- 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.
- Open Visual Studio 2013+
- Click File >> Create a New project
- Click on Visual C# for choosing the language
- Click on "Test" for creating a test project.
- Select Unit Test Project Template. Create the project with a suitable name
- Open your project and click on Tools on topbar of Visual Studio.
- Click on NuGet Package Manager.
- Click on Manage NuGet Package for the solution.
- Search Selenium On Browse content of NuGet UI.
Install Selenium.webDriver to your solutions,
- Search with Selenium.Chrome.WebDriver on Browser UI,
Install Selenium.Chrome.WebDriver,
- 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.
- Go to the driver folder
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.
- Go to your project and the open your UnitTest1.cs (Default)
Paste the below code.
- [TestClass]
- public class UnitTest1
- {
- [TestMethod]
- public void TestMethod1()
- {
-
- IWebDriver driver = new ChromeDriver(@"C:\Users\Suman\FirstSeleniumDemo\packages\Selenium.Chrome.Web Driver.2.40\driver");
- driver.Navigate().GoToUrl(@"https://www.c-sharpcorner.com/");
- }
- }
Now, run the test case.
You can open a website using Selenium Chrome driver using C# note.
Thanks a lot.