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 and Adding gecko driver exe to execute scripts on Firefox Browser.
In this article, I am going to add IE driver (an exe file) to execute our Selenium C# Test Automation scripts in Internet Explorer browser.
Let’s get started.
Selenium C# – Adding IE driver to execute scripts on Internet Explorer Browser
Follow the below steps for executing test automation scripts in Internet Explorer Browser:
1) Download IE 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 a bit and download 64-bit version of IE Driver as shown below:
4) Extract the Zip file which got downloaded in the previous step as shown below:
5) Observe that a IEDriverServer.exe file will get extracted from the above ZIP file as shown below:
6) Launch Visual Studio, open the Project in which Selenium is installed (Refer previous article):
7) Now copy the IEDriverServer.exe file extracted in the above step 5 and paste into the ‘Drivers’ folder as shown below:
8) Comment out the existing ChromeDriver object creation step & FirefoxDriver object creation step as shown below and create an object for InternetExplorerDriver predefined Class of Selenium and observe that errors will be displayed as shown below:
9) Hover the mouse on InternetExplorerDriver class and select to use OpenQA.Selenium.IE; to resolve the above errors as shown below:
10) Observe that the errors got resolved as shown below:
11) Now, copy the path of IEDriverSever EXE file by following the below steps:
12) Right click on ‘IEDriverServer.exe’ file and select ‘Properties’ option as shown below:
13) Copy the path of IEDriverServer.exe from the Properties pane as shown below:
14) Paste the path into the InternetExplorerDriver() constructor in InternetExplorerDriver object creation statement as shown below:
15) To resolve the error in the above pasted path, add @ and observe that the errors got resolved as shown below:
16) Remove ‘IEDriverServer.exe’ from the above path and keep the path till \Drivers\ as shown below:
17) Save the Program.cs file and click on ‘Start’ option to execute the Selenium C# Script as shown below:
18) If you are getting the below error ‘Exception Unhandled – System.InvalidOperationException: ‘Unexpected error launching Internet Explorer. Protected Mode Settings are not the same for all zones. Enable Protected Mode must be set the same value (enabled or disabled) for all zones. (SessionNotCreated)’ as shown below:
19) Open Internet Explorer Browser in your machine and select ‘Tools > Internet Options’ from as shown below:
20) In the displayed ‘Internet Options’ dialog, click on ‘Security’ tab and select ‘Internet’ option and make sure that ‘Enabled Protected Mode’ check box option is selected as shown below:
21) In the similar manner, select other options ‘Local Intranet’, ‘Trusted Sites’ and ‘Restricted sites’ and make sure that the ‘Enable Protected Mode’ option is selected and click on ‘Apply’ button as shown below:
22) Close the Internet Explorer Browser and repeat the Step 17 to execute the Automation Script and observe that this time a blank Internet Explorer Browser will be launched 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.
23) In the above code, we can generalize the IE Driver Path, instead of giving the complete path of IEDriverServer EXE file from Root Drive as shown below:
InternetExplorerDriver driver = new InternetExplorerDriver(@"../../" + "/Drivers/");
Save and click on the ‘Start’ button to execute the updated statement having generalized IEDriverServer 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 Internet Explorer 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.