HomeSelenium C#

Selenium C# – Adding gecko driver exe to execute scripts on Firefox Browser

Selenium C# – Adding gecko driver exe to execute scripts on Firefox Browser

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

In our previous articles, I have explained how to install Selenium for C# in Visual Studio and also explained Adding chrome driver to execute scripts on Chrome Browser.

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

Let’s get started.

Selenium C# – Adding Gecko driver to execute scripts on Firefox Browser

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

1) Download Gecko 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 ‘Mozialla GeckoDriver > Latest’ link as shown below:

Selenium CSharp - Latest GeckoDriver

 

4) GeckoDriver releases page will be displayed with the so far latest version of GeckoDriver on the top of the page as shown below:

Selenium CSharp - Latest GeckoDriver Version

5) Scroll  down at bit and download the ‘Windows 64 bit version of GeckoDriver’ as shown below:

Selenium CSharp - 64 Bit

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

Selenium CSharp - Extract Here

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

Selenium CSharp - geckodriver exe file

8) Download and install the latest version of Firefox Browser and make sure that your Firefox Browser is up to date as shown below:

Selenium CSharp - Up to date

9) Launch Visual Studio, open the Project in which Selenium is installed (Refer previous article):

Selenium CSharp - Open Project

10) Now copy the geckodriver.exe file extracted in the above step 7 and paste into the ‘Drivers’ folder as shown below:

Selenium CSharp - geckodriver exe pasted

11) Comment out the existing ChromeDriver object creation step as shown below and create an object for FirefoxDriver predefined Class of Selenium and observe that errors will be displayed as shown below:

Selenium CSharp - Firefox Driver Object

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

Selenium CSharp - Import

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

Selenium CSharp - Errors Resolved

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

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

Selenium CSharp - Properties

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

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

Selenium CSharp - Paste the Path

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

Selenium CSharp - At the rate

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

Selenium CSharp - Remove geckodriver from path

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

Selenium CSharp - Execute

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

Selenium CSharp - Blank Firefox

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

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

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

Selenium CSharp - Optimized Path

Here conclude our article and we were able to successfully execute Selenium C# Test Automation Script in Visual Studio on Firefox Browser.

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 *