• Skip to main content
  • Skip to primary sidebar
  • Skip to footer
  • Home
  • Programming Languages
    • Java Tutorials
    • Python Tutorials
    • JavaScript Tutorials
  • Automation Tools and Different Tools
    • Web Automation
      • Selenium with Java
        • Selenium Basic
        • Selenium Advance
        • Selenium Realtime
        • Framework
        • Selenium Interview
        • Selenium Videos
        • Selenium with Docker
      • Selenium with Python
      • WebdriverIO
        • Selenium Webdriver C# Tutorial
      • Cypress
      • Playwright
    • TestNG
    • Cucumber
    • Mobile Automation
      • Appium
    • API Testing
      • Postman
      • Rest Assured
      • SOAPUI
    • testRigor
    • Katalon
    • TestProject
    • Serenity BDD
    • Gradle- Build Tool
    • RPA-UiPath
    • Protractor
    • Windows Automation
  • Automation For Manual Testers
  • Services
  • Online Training
  • Contact us
  • About me
  • Follow us
    • Linkedin
    • Facebook Group
    • Facebook Page
    • Instagram

Automation

Selenium WebDriver tutorial Step by Step

You are here: Home / Selenium with C# / Complete Guide To Install Selenium Webdriver With C# with Visual Studio

Complete Guide To Install Selenium Webdriver With C# with Visual Studio

August 22, 2018 by Mukesh Otwani 27 Comments

Install Selenium with C# When I started my Test Automation journey I started Selenium with Java and then I also explored Selenium with Python and with C# as well. Before we start Install Selenium Webdriver With C# let us discuss few things about what is Selenium and C# and few more points

What is Selenium

Selenium is a portable software testing suite for web applications. Primarily, it is for automating web applications for testing purpose, but it certainly not limited to just that. Selenium is open source. Selenium is highly flexible. There are many ways you can add functionality to both Selenium test scripts and Selenium’s framework to customize your test automation i.e. We can modify the built-in selenium functions based on our requirement. This is perhaps Selenium’s greatest strength when compared with other automation tools. Selenium is a set of different software tools each with a different approach to supporting test automation. It has 4 components.
  1. Selenium Integrated Development Environment (IDE).
  2. Selenium Remote Control (RC).
  3. Selenium WebDriver.
  4. Selenium Grid.
Selenium Scripts can be written in any programming languages like C#, Groovy, Java, Perl, PHP, Python, Ruby, JavaScript. Selenium Scripts can run on any browser like Mozilla Firefox, Internet Explorer, Google Chrome, Microsoft Edge, Safari or Opera. Selenium Scripts can run on OS like Windows, Mac, Android or Linux.

What is C#

C# is a general Object-Oriented Programming (OOP) language for networking and Web development. C# is specified as a Common Language Infrastructure (CLI) language. C# is highly expressive, yet it is also simple and easy to learn. C# syntax simplifies many complexities of C++. For more detailed information of C# please refer following links
https://docs.microsoft.com/en-us/dotnet/csharp/getting-started/introduction-to-the-csharp-language-and-the-net-framework.
https://www.javatpoint.com/c-sharp-tutorial.
  1. Differences between Selenium with C# and Selenium with Java?
There is no Major differences between Selenium with Java and Selenium with C#.
Selenium with Java Selenium with C#
In Selenium with Java we have WebDriver to create web browser instance. In Selenium with C# we have IWebDriver to create web browser instance.
In Selenium with Java we use WebElement to find out web elements in the application. In Selenium with C# we use IWebElement to find out web elements in the application.
In Selenium with Java we use @FindBy annotation is used in Page Objects in Selenium tests to specify the object location strategy for a WebElement or a list of WebElements. In Selenium with C# we use [FindBy] annotation is used in Page Objects in Selenium tests to specify the object location strategy for a WebElement or a list of WebElements.

IDE used for C#

C# development can be done using many IDEs like Visual Studio, MonoDevelop, #develop, Rider and Many more. In this tutorial we will develop C# in Visual Studio.  

How to Install Visual Studio in windows?

Let’s download and install visual studio in following steps. Step 1: Download the latest Visual Studio from the following link https://www.visualstudio.com/downloads/. Download Visual Studio Its preferable to download Visual Studio Community 2017 or Visual Studio Professional 2017 (30days free trail). Step 2: Once its downloaded, click on the executable(.exe) file. save exe Step 3: Next, click on continue. Click On Continue Step 4: Visual Studio will start downloading the initial files. Installer Step 5: In next screen, click on install. Community Edition   Step 6: In next screen select .NET desktop development and click on install.   select dot net Step 7: Visual Studio will download .NET desktop development related files. Wait for download Step 8: Once download is completed. It will ask for Reboot. reboot required Step 9: After Reboot Open Visual Studio   . It will ask for sign in or sign up. If you Microsoft account sign in else click on Not now, may be later link. Sign in Required Step 10: In next screen, Select General from dropbox and select the color theme of your choice and click on Start Visual Studio button. theme select Step 11: Visual Studio is ready to use. You can now create C# Project by clicking on new Project and by giving name to it. get started  

Install Selenium Webdriver With C#

Let’s see how to write “Hello World!!” Program in C#. Step 1: Launch Visual Studio. Start->Visual Studio ->click. It will launch Visual Studio. Step 2: Click on File-> New -> Project. new project Step 3: Next screen project name 1.Give project name. 2.Select the folder where you want project to be saved. 3.Click on OK button. Project will be created with name HelloWorld.   Step 4: After creation of project screen looks like below  sample project first look Keywords:
  1. using – using keyword is used to include namespace in the program.
  2. namespace – namespace is a collection of classes. HelloWorld namespace contains the class Program.
  3. class – class contains different data and method definitions.
  4. Main – Main method is an entry point for C# programs. Execution starts from Main method.
  Step 5: Add Console.WriteLine(“Hello World!!”) to the above project. console write line Console.WriteLine() is used to print message in console. Save the program and press F5 to execute the program. A command prompt window will appear that contains the line Hello Word!! The execution of the program will be too fast. To see console output Debug-> Start Without Debugging or Ctrl+F5. Output Screen will be like below. output  

How to Install Selenium to Visual Studio?

There are two ways of installing Selenium to Visual Studio.
  1. Downloading Selenium libraries from seleniumhq.org.
  2. Downloading Selenium via NuGet Package Manager.
  Let’s see installation of selenium with Visual studio by downloading via NuGet Package Manager with an example. Create C# project by using steps mentioned in Section 7. Step 1: Create a new project called FirstProgram using above mentioned steps. create selenium project   Step 2: Navigate to Tools-> NuGet Package Manager-> Manager NuGet Packages for Solution… NuGet package manager   Step 3: In next screen search for selenium
  1. Select Browse tab.
  2. Enter Selenium in search field.
  3. Selenium latest Selenium.WebDriver available.
  4. Select the project created in step 1(i.e FirstProgram)
  5. Click on Install.
Step 4: In next screen click on OK button. preview Step 5: Once WebDriver is installed. We should get following message. downloading confirm Step 6: Once WebDriver is installed let’s install ChromeDriver. Tools-> NuGet Package Manager-> Manager NuGet Packages for Solution… NuGet package manager for Chrome Driver
  1. Enter ChromeDriver in search field.
  2. Select the ChromeDriver.
  3. Select the project created.
  4. Click on Install.
search for Chrome Driver In Next screen click on OK button. chromedriver confirmation Once ChromeDriver is installed. We will get the following message. chromedriver download   Step 7: Selenium is installed to FirstProgram. Now let’s write code to perform goggle search. Code Explanation.
            // Create a driver instance for chromedriver
            IWebDriver driver = new ChromeDriver();

            //Navigate to google page
            driver.Navigate().GoToUrl("http:www.google.com");

            //Maximize the window
            driver.Manage().Window.Maximize();

            //Find the Search text box using xpath
            IWebElement element = driver.FindElement(By.XPath("//*[@title='Search']"));

            //Enter some text in search text box
            element.SendKeys("learn-automation");

            //Close the browser
            driver.Close();
Install Selenium Webdriver With C# Navigate to Start button on the top and click on it. It will launch console 1st and after few seconds it will launch ChromeDriver and will perform action mentioned in the code. run Selenium Program We will get output as shown below. final output

Filed Under: Selenium with C# Tagged With: Install Selenium Webdriver With C#

Reader Interactions

Comments

  1. Sonal says

    May 18, 2023 at 10:14 AM

    Thanks, It’s really a very well documented each and every steps.
    Any clue for Lambda automation using c#, please.

    Reply
    • Mukesh Otwani says

      July 24, 2023 at 12:23 AM

      Hi Sonal, Thank you so much. C# I stopped from long time. You can check executeautomation.com for Selenium with C#.

      Reply
  2. Myroslav says

    March 16, 2022 at 7:40 PM

    Hi,
    Maybe I am doing something wrong, but my test fail with Message:
    ► System.InvalidOperationException : session not created: This version of ChromeDriver only supports Chrome version 85 (SessionNotCreated)

    I cannot understand where I have to set up my Chrome version

    Reply
    • Mukesh Otwani says

      March 17, 2022 at 12:14 PM

      Hi Myroslav, please update chromedriver because current Chrome version is 99 and coming version is 100 so we need compatible drivers for the same.

      Reply
      • MrPittala says

        July 20, 2022 at 7:04 PM

        Hi Mukesh,

        First of all Thanks a lot for the step-by-step explanation. It helped me.

        I tried the same way but was unable to fix the issue “System.InvalidOperationException : session not created: This version of ChromeDriver only supports Chrome version 85 (SessionNotCreated)”
        the current version of Google is 103, could you please check again and help.

        Regards,
        Madhu

        Reply
        • Mukesh Otwani says

          July 22, 2022 at 1:06 PM

          Hi Madhu, start using WDM to fix this issue.

          Reply
  3. Tetiana says

    April 6, 2021 at 3:53 AM

    Thank you so much! Nice explanation. I have successfully run at first attempt.

    Reply
    • Mukesh Otwani says

      April 6, 2021 at 8:12 AM

      Great…:)

      Reply
  4. Mark says

    June 19, 2020 at 10:10 PM

    Thank you so much! Your article really helped me a lot for my work! Again, thank you so much! God bless!

    Reply
    • Mukesh Otwani says

      June 20, 2020 at 5:07 PM

      Hi Mark,

      Thanks for your kind words. Frankly, you made my day…:)
      Please feel free to ask your doubts and I’ll try my level best to clarify it.

      Reply
  5. Ernest says

    April 28, 2020 at 1:33 AM

    I`ve started to use WebDriver with these instructions (https://www.brainbeast.best/faq-about-selenium-webdriver-on-c-sharp-with-examples/) which require driver exe file to be downloaded from chromedriver.chromium.org. But i don`t get how you`ve managed to dowload it from VS.

    Reply
    • Mukesh Otwani says

      April 28, 2020 at 1:05 PM

      Hi Ernest,

      Hope you have gone through my post

      Reply
  6. Antonio says

    April 13, 2020 at 10:27 PM

    I would suggest to update the XPath since google seems to dynamically change element attributes:

    IWebElement element = driver.FindElement(By.XPath(@”/html/body/div/div[3]/form/div[2]/div[1]/div[1]/div/div[2]/input”));

    Reply
    • Mukesh Otwani says

      April 14, 2020 at 6:51 AM

      Hi Antonio,

      Use dynamic XPath instead of absolute…

      Reply
  7. Bhavesh Shah says

    March 31, 2020 at 1:32 AM

    Hi Mukesh,
    can you please share any your material for api automation?

    Reply
    • Mukesh Otwani says

      March 31, 2020 at 9:57 AM

      Hi Bhavesh,

      Please refer this playlist https://www.youtube.com/watch?v=aqrxDxumKZQ&list=PL6flErFppaj08LFolWioWyjfSGtCWcvVp for API tutorial videos

      Reply
  8. sam says

    December 4, 2019 at 5:19 AM

    if i want to use same technology for angular js pages, what are the add on’s i need to do here?

    Reply
    • Mukesh Otwani says

      December 4, 2019 at 2:56 PM

      Hi Sam,

      For Angular js apps, Protractor with TypeScript is best to automate…

      Reply
  9. sai says

    September 17, 2019 at 11:09 PM

    Hi Bro,

    Same thing how to run on internetedge in Win10

    Thanks

    Reply
    • Mukesh Otwani says

      September 18, 2019 at 10:39 AM

      Hi Sai,

      Please check this link https://social.msdn.microsoft.com/Forums/sqlserver/en-US/a6749b18-12c1-4d16-bdbc-35b21adb9e7d/seleniun-c-using-ms-edge-webdriver?forum=vstest

      Reply
  10. Elena says

    August 3, 2019 at 1:38 AM

    Thank you!

    Reply
  11. Syed Ameer says

    June 3, 2019 at 4:42 AM

    Thanks for sharing your knowledge,May God bless for your bright Future

    Reply
    • Mukesh Otwani says

      June 3, 2019 at 10:33 AM

      Thanks for wishes, Syed…:)

      Reply
  12. Renuka says

    March 28, 2019 at 10:32 PM

    Hi Mukesh,

    Thanks for the learning sessions which you share. Very easy to understand and gives confidence.

    Can you please share details on how to create a BDD Framework using selenium and C#

    Thanks

    Reply
    • Mukesh Otwani says

      March 29, 2019 at 5:41 AM

      Hi Renuka,

      Thanks for your appreciation…:)
      BTW may tutorials on C# are under pipeline.

      Reply
  13. Imran says

    October 3, 2018 at 8:22 AM

    Thanks for sharing your knowledge, I have successfully run at first attempt, one question is there any framework like TestNG?

    Reply
    • Mukesh Otwani says

      October 3, 2018 at 9:11 AM

      Hi Imran,

      TestNG is inspired(but enhanced) from JUnit. Mostly for automation, TestNG is preferred. In terms of Design Pattern, there are multiple approaches for it. Please refer this link https://www.journaldev.com/1827/java-design-patterns-example-tutorial.

      Reply

Leave a Reply Cancel reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Primary Sidebar

Free Selenium Videos

Video Player
https://www.youtube.com/watch?v=w_iPCT1ETO4
00:00
00:00
31:21
Use Up/Down Arrow keys to increase or decrease volume.

Search topic

Top Posts & Pages

  • Selenium Webdriver tutorial for beginners
  • How To Fix Eclipse Autocomplete Or Code Suggestion In Eclipse
  • Selenium Webdriver C# Tutorial
  • WHAT ARE YOUR EXPECTATIONS FROM US?

Stay connected via Facebook

Archives

Footer

Categories

Recent Post

  • API Testing Using Postman And RestAssured
  • Disable Personalise Your Web Experience Microsoft Edge Prompt In Selenium
  • How To Fix Error: No tests found In Playwright
  • How To Fix Eclipse Autocomplete Or Code Suggestion In Eclipse
  • Best and easy way to Group test cases in selenium

Top Posts & Pages

  • Selenium Webdriver tutorial for beginners
  • How To Fix Eclipse Autocomplete Or Code Suggestion In Eclipse
  • Selenium Webdriver C# Tutorial
  • WHAT ARE YOUR EXPECTATIONS FROM US?