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:
3) In the displayed ‘Download’ page, scroll down and click on the ‘Mozialla GeckoDriver > Latest’ link as shown below:
4) GeckoDriver releases page will be displayed with the so far latest version of GeckoDriver on the top of the page as shown below:
5) Scroll down at bit and download the ‘Windows 64 bit version of GeckoDriver’ as shown below:
6) Extract the Zip file which got downloaded in the previous step as shown below:
7) Observe that a geckodriver.exe file will get extracted from the above ZIP file as shown below:
8) Download and install the latest version of Firefox Browser and make sure that your Firefox Browser is up to date as shown below:
9) Launch Visual Studio, open the Project in which Selenium is installed (Refer previous article):
10) Now copy the geckodriver.exe file extracted in the above step 7 and paste into the ‘Drivers’ folder as shown below:
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:
12) Hover the mouse on FirefoxDriver class and select to use OpenQA.Selenium.Firefox; to resolve the above errors as shown below:
13) Observe that the errors got resolved as shown below:
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:
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:
18) To resolve the error in the above pasted path, add @ and observe that the errors got resolved as shown below:
19) Remove ‘chromedriver.exe’ from the above path and keep the path till \Drivers\ as shown below:
20) Save the Program.cs file and click on ‘Start’ option to execute the Selenium C# Script as shown below:
21) Observe that a blank chrome browser will be displayed as shown below:
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:
FirefoxDriver driver = new FirefoxDriver(@"../../" + "/Drivers/");
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.
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.
- > 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 ?
On a mission to contribute to the Software Testing Community in all possible ways.