HomeSelenium C#

Selenium C# – Adding Chrome driver to execute scripts on Chrome Browser

Selenium C# – Adding Chrome driver to execute scripts on Chrome Browser

<<Previous Post                            << Complete Tutorial>>                              Next Post>>

In our previous article, I have explained how to install Selenium for C# in Visual Studio.

In this article, I am going to add chrome driver (an exe file) to execute our Selenium C# Test Automation scripts in chrome browser.

Let’s get started.

Selenium C# – Adding Chrome driver to execute scripts on Chrome Browser

Follow the below steps for executing test automation scripts in Chrome Browser:

1) Download Chrome Driver by following the below steps.

2) Open https://www.seleniumhq.org in any browser say Chrome and click on the ‘Download’ tab as shown below:

Selenium C# - SeleniumHQ Website

3) In the displayed ‘Download’ page, scroll down and click on the ‘Google Chrome Driver’ > ‘latest’ link as shown below:

Selenium C# - Chrome Driver Latest Link

The following page will be displayed:

Selenium C# - Chrome Drivers Page

Before downloading the Chrome Driver version from the above page, we need to first findout the Chrome Browser version in your machine by following the below steps.

4) Download the chrome driver version that matches with your chrome browser version by following the below steps:

Open Chrome browser and select three dots > Help > About Google Chrome (as shown below)

Selenium C# - About Google Chrome

Observe that the Google Chrome version you are using currently will be displayed as shown below:

Selenium C# - Google Chrome Version

As the Chrome Browser version (i.e. Version 75 in our case) should match with the Chrome Driver version (Version 75 should be selected), lets click on the below version:

Selenium C# - Chrome Driver 75

 

5) In the displayed page, click on the Windows related link to download as shown below:

Selenium C# - Windows Chrome Driver 75

 

6) Extract the Zip file which got downloaded in the previous step as shown below:

Selenium C# - Extract Chrome Driver Zip File

7) Observe that a chromedriver.exe file will get extracted from the above ZIP file as shown below:

Selenium C# - Chrome Driver EXE File

8) Launch Visual Studio, open the Project in which Selenium is installed (Refer previous article) and right click on the Project in Solution Explorer & select Add > New Folder option as shown below:

Selenium C# - Add New Folder

9) Provide the name of the folder as anything say ‘Drivers’ as shown below:

Selenium C# - Drivers

10) Now copy and paste the chromedriver.exe downloaded earlier (step 7) into this ‘Drivers’ folder as shown below:

Selenium C# - Chrome Driver EXE File Pasted

11) Create an object for ChromeDriver predefined Class of Selenium and observe that errors will be displayed as shown below:

Selenium C# - ChromeDriver Object Statement

12) Hover the mouse on ChromeDriver class and select to use OpenQA.Selenium.Chrome; to resolve the above errors as shown below:

Selenium C# - OpenQA Selenium Chrome

13) Observe that the errors got resolved as shown below:

Selenium C# - Errors Resolved

14) Now, copy the path of ChromeDriver EXE file by following the below steps

15) Right click on ‘chromedriver.exe’ file and select ‘Properties’ option as shown below:

Selenium C# - Select Properties Option

16)  Copy the path of chromedriver.exe from the Properties pane as shown below:

Selenium C# - Path Copy

17) Paste the path into the ChromeDriver() constructor in ChromeDriver object creation statement as shown below:

Selenium C# - Path Paste

18) To resolve the error in the above pasted path, add @ and observe that the errors got resolved as shown below:

Selenium C# - At the rate

19) Remove ‘chromedriver.exe’ from the above path and keep the path till \Drivers\ as shown below:

Selenium C# - Updated Path

20) Save the Program.cs file and click on ‘Start’ option to execute the Selenium C# Script as shown below:

Selenium C# - Save Start

 

21) Observe that a blank chrome browser will be displayed as shown below:

Selenium C# - Blank Google Chrome

The above blank Chrome Browser will be launched when ChromeDriver(“Path of ChromeDriver EXE file”) constructor is executed in our Selenium C# Automation script.

22) In the above code, we can generalize the Chrome Driver Path, instead of giving the complete path of ChromeDriver EXE file from Root Drive as shown below:

Save and click on the ‘Start’ button to execute the updated statement having generalized ChromeDriver EXE file path and observe that the program will be executed and a blank browser will be launched as expected.

Selenium C# - Generalized Chrome Driver PathSelenium C# - Generalized Chrome Driver Path

 

 

 

 

 

 

Here conclude our article and we were able to successfully test our first Selenium C# Test Automation Script in Visual Studio.

I will explain more Selenium C# Automation Scripts for performing different operations on the web pages like navigating to the Web Applications, performing click, type & other operations on the UI elements on the Web Application pages in the upcoming articles.

Next Steps:

  • > To learn more about Selenium C#, continue to the next post (Click on Next Post Link Below)
  • > Check complete Selenium C# Tutorial Contents here (Click here)

Please leave your questions/comments/feedback below.

Happy Learning 🙂

About Me > Naveen Repala

Connect to me on Linked In (Click here)

On a mission to contribute to the Software Testing Community in all possible ways.

<<Previous Post                            << Complete Tutorial>>                              Next Post>>

If you like this article, share it on LinkedIn using the below button:

Comments (0)

Leave a Reply

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