Running Tests on Selenium in Internet Explorer is quite easy. We have to communicate with Internet Explorer to launch Internet Explorer through Internet Explorer driver.
Internet Explorer Driver Server
Internet Explorer Driver Server is a link between your selenium scripts and the Internet Explorer browser. You wonāt be able to communicate with the Internet Explorer browser, without running the server on your system.
The Internet Explorer driver server is a tiny application created by the Selenium WebDriver team. As Internet Explorer does not have an API or native implementation in Java, they had no choice but to create a server. IE Driver Server implements the WebDriver protocol, which is a W3 standard that gives basic guidance on how a browser can expose itself for programmatic access.
This WebDriver protocol also mandates an interface that is language-independent, so that the browser can be controlled externally via any programming language of your choice. To learn more about implementing this in automation, consider enrolling in a Selenium certification course for deeper insights and hands-on practice.
In a nutshell, Selenium WebDriver implementation says that by sending HTTP command requests you can control a web browser so that each command will perform something to direct the browser. This is exactly will do the same that Internet Explorer driver server does, which starts a server and then waits for the commands.
Download and Install Internet Explorer Driver
Internet Explorer driver server is an executable file that needs to have in any one of your system paths before running your selenium tests. To download the latest version of Internet Explorer Driver we need to follow the below steps:
Step1: Go to the official website of Internet Explorer driver (https://www.selenium.dev/downloads/) and download the appropriate version for Internet Explorer driver based on your operating system.
Note: Based on your Windows Operating System, you need to download the corresponding IE Driver of Windows version. Here we are working on the Windows Operating system; you need to download the Windows version IE driver. If your operating system is Mac or Linux then you need to download the corresponding Internet Explorer driver which is compatible with your test environment.
Step2: Download 32 bit Windows IE or 64 bit Windows IE based on your Operating System to download IE driver for Windows Operating System.
Step3: Extract the ZIP file, once the ZIP file download is complete.
Step4: To instantiate the driver, you need to note down the location where you extracted the IE Driver.
Points to remember when working with IE browser
Below are the two points to remember when working with IE browser
- The Zoom level should be set to 100%
- The Protected mode should be turned off and make a level to least positions ie to the bottom down position.
Using Selenium WebDriver, we may fail to launch an IE driver when we run your Selenium WebDriver Scripts in the Internet Explorer browser. When you wonāt set above two points you may face below two errors when you run your Selenium WebDriver Scripts in the IE browser.
Failed to Launch the Internet Explorer Driver using Selenium WebDriver
Running Tests on Selenium can sometimes present challenges, especially when users attempt to launch an IE driver using Selenium WebDriver. These issues are common, but with the right configurations, they can be resolved. To overcome these frequent obstacles, here are solutions to the issues that many users encounter, helping ensure a smooth and successful test execution on Internet Explorer.
Error 1:
Exception in threadĀ āmainā org.openqa.selenium.remote.SessionNotFoundException: Unexpected error launching in the Internet Explorer.Ā In the Internet Explorer browser for all zones Protected Mode settings are not the same. The same value must be set for all the zones in the Protected Mode.
Solution:Ā
To resolve the above error, we need to enable the protected mode and the mode should be turned off and make a level to least positions i.e to bottom down position for all the zones.
Follow the below steps to enable protected mode for all the zones.
Step 1: Open the Internet Explorer
Step 2: Go to Tools option and Click on Internet Options
Step 3: Select Security Tab
Step 4: ChooseĀ Internet option inĀ Select a zone to view or change security settingsĀ and select the checkbox ofĀ Enable protected modeĀ (requires restarting Internet Explorer).
Step 5:Ā Similarly for other three optionsĀ Local Intranet, Trusted sites, and Restricted sites, select the checkbox ofĀ Enable protected modeĀ (requires restarting Internet Explorer)
Error 2:
Exception in threadĀ āmainā org.openqa.selenium.remote.SessionNotFoundException: Unexpected error launching in the Internet Explorer.Ā The browser zoom level was set to 200%. It should be set to 100%
Solution:Ā
To fix the above error, we need to set the Zoom level to 100% of the Internet Explorer browser.
Follow the below steps to set the Zoom level to 100%.
Step 1:Ā OpenĀ the Internet Explorer
Step 2:Ā Go to ToolsĀ menu āĀ Select Zoom (100%) ā Select 100%
Launching Internet Explorer browser using Selenium WebDriver
Setting up the webdriver.ie.driver property
Selenium WebDriver has a class called InternetExplorerDriver which is used to launch and control the Internet Explorer browser. The code to launch IE Driver is the same as you launch a ChromeDriver and GeckoDriver. All you need to set a system property āwebdriver.ie.driverā to the path of executable file āIEDriverServer.exeā. If you havenāt done this, you will face an error āThe path to the driver executable must be set by the webdriver.ie.driver system propertyā.
Let’s create a test case in which we will automate the following scenarios to handle Drop-downs:
- Invoke a Google chrome browser.
- Open URL: https://www.facebook.com/
- Print the Title of the webpage.
- Close the browser.
Now, we will create a test case step by step in order to understand of how to handle drop-downs in WebDriver.
Step 1: Launch Eclipse IDE.
Step 2: Go to File > New > Click on Java Project.
Step 3: Right click on the Project Name and click on the New > class.
Name: InternetExplorerTest
Step 4: Invoke the Google Chrome browser and set the system property to the path of your chromedriver.exe file.
Here is the sample code to set Chrome driver system property:
// System Property for Chrome Driver
System.setProperty(“webdriver.chrome.driver”, ā D:\\Drivers\\geckodriver.exe “);Ā Ā
After that we have to initialize the Chrome driver using ChromeDriver Class. Below is the sample code to initialize Chrome driver using ChromeDriver class.
// Instantiate a ChromeDriver class.
WebDriver driver=new ChromeDriver();Ā Ā
We will get the below code to launch Google Chrome browser after combining both of the above codes.
System.setProperty(“webdriver.chrome.driver”, ā D:\\Drivers\\geckodriver.exe “);
WebDriver driver=new ChromeDriver();Ā Ā
After that we need to navigate to the desired URL.
Below is the sample code to navigate to the desired URL:
// Launch Website
driver.navigate().to(“https://www.facebook.com/“);Ā
Here is the complete code for the above scenario:
import org.openqa.selenium.WebDriver;Ā Ā import org.openqa.selenium.chrome.ChromeDriver;Ā Ā public class InternetExplorerTest{Ā Ā Ā Ā Ā Ā public static void main(String[] args) {Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā // System Property for Chrome DriverĀ Ā Ā Ā System.setProperty("webdriver.chrome.driver", ā D:\\Drivers\\geckodriver.exe ");Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā // Instantiate a ChromeDriver class.Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā WebDriver driver=new ChromeDriver();Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā // Launch WebsiteĀ Ā driver.navigate().to("https://www.facebook.com/");Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā }Ā Ā Ā Ā }Ā
Step 5: Print the Title of the webpage
Step 6: Close the driver
Below is the program to launch the Internet Explorer Driver
package com.testing.selenium.InternetExplorer; import org.openqa.selenium.WebDriver; import org.openqa.selenium.ie.InternetExplorerDriver; public class InternetExplorerTest { Ā Ā Ā Ā public static void main(String[] args) { Ā Ā Ā Ā System.setproperty("Webdriver.ie.driver","D:\\Drivers\\IEDriverServer.exe"); Ā Ā Ā Ā WebDriver driver = new InternetExplorerDriver(); Ā Ā Ā Ā driver.get("https://facebook.com"); Ā Ā Ā Ā String PageTitle = driver.getTitle(); Ā Ā Ā Ā System.out.println("Page Title is:" + PageTitle); Ā Ā Ā Ā driver.close(); Ā Ā Ā Ā } Ā }
When you run the above program it will open the facebook.com website in the new Internet Explorer window and print the website title in the console.
Internet Explorer Options
- requireWindowFocus():Ā
This option configures whether to require the IE window to have input focus before performing any user interactions like mouse or keyboard events.Ā
Parameters: requireĀ booleanĀ Whether to require window focus.
Returns Options
A self reference.
Source:
requireWindowFocus(require) { Ā Ā Ā Ā Ā this.options_[key.REQUIRE_WINDOW_FOCUS] = ! ! require; Ā Ā Ā Ā Ā return this; }
2. ignoreZoomSetting():
Indicates whether to check that the browserās zoom level is set to 100%
Parameters: ignore Boolean
Whether to ignore the browserās zoom level settings.
Returns:Ā Options
A self reference.
Source:
ignoreZoomSetting(ignore) { Ā Ā Ā Ā Ā this.options_[key.IGNORE_ZOOM_SETTING] = ! ! ignore; Ā Ā Ā Ā Ā return this; }
3. Options.ie():
Parameters: None
Returns: Capabilities
Ā Ā Ā Ā Ā Ā Ā A basic set of capabilities for Internet Explorer
@return {!Capabilities}Ā A basic set of capabilities for Internet Explorer. static ie() { return new Capabilities().setBrowserName(Browser.INTERNET_EXPLORER); }
4. setPageLoadStrategy:
Sets the desired page loading strategy for a new WebDriver session.
Source:
Sets the desired page loading strategy for a new WebDriver session. @param {PageLoadStrategy} strategy the desired strategy @return {!Capabilities} a self reference setPageLoadStrategy(strategy) { return this.set(Capability.PAGE_LOAD_STRATEGY, strategy); }
5. setProxy:
Sets the proxy configuration for this instance
@param {proxy.Config} proxy The desired proxy configuration @return {!Capabilities} A self reference setProxy(proxy) { return this.set(Capability.PROXY, proxy); }
6. setExtractpath:
Set the path of the temporary data directory to use.
@param {string} path the log file path @return {!Options} A self reference setExtractPath(path) { this.options_[Key.EXTRACT_PATH] = path; return this; }
7. setHost:
Sets the IP address of the driverās host adapter
@param {string} host the IP address to use @return {!Options} A self reference setHost(host) { this.options_[Key.HOST] = host; return this; }
8. setLogFile:
Sets the path to the log file the driver should log to.
@param {string} file The log file path. @return {!Options} A self reference. setLogFile(file) { this.options_[Key.LOG_FILE] = file; return this; }
9. setLogLevel:
Set the IEDriverServer’s logging {@linkplain Level level}.
@param {Level} level The logging level. @return {!Options} A self reference. Ā Ā Ā Ā Ā setLogLevel(level) { Ā Ā Ā Ā this.options_[Key.LOG_LEVEL] = level; Ā Ā Ā Ā return this; Ā Ā }
10. initialBrowserURL:
Sets the initial URL loaded when IE starts.
@param {string} url The initial browser URL. @return {!Options} A self reference. Ā Ā Ā Ā Ā initialBrowserUrl(url) { Ā Ā Ā Ā this.options_[Key.INITIAL_BROWSER_URL] = url; Ā Ā Ā Ā return this; Ā Ā }
Conclusion
In conclusion, running tests on Selenium using the Internet Explorer browser requires careful setup due to IEās unique handling of web elements and compatibility considerations. By using the IE Driver Server, Selenium enables automation on Internet Explorer, even though the browser lacks a native Java API. Ensuring correct configurations such as setting security levels, managing protected mode, and handling pop-ups is essential for stable test execution on IE.
While IE is less commonly used than other browsers, it remains critical for testing applications in environments where compatibility is a priority. Mastering these configurations and understanding IE-specific behaviors can improve the reliability of automated tests, making your Selenium testing suite versatile across different browser platforms.
Call to Action
Ready to master running tests on Selenium using the Internet Explorer browser? Join H2K Infosys and gain hands-on experience in configuring and executing tests across different browsers, including Internet Explorer. Our expert-led Selenium certification courses provide in-depth training, covering everything from IE Driver Server setup to handling unique IE challenges in test automation. Elevate your skills and ensure your test suite is compatible across various browsers, preparing you for real-world projects. Enroll today with H2K Infosys to become a skilled Selenium automation professional!