All IT Courses 50% Off
Selenium Tutorials

Running Tests on Selenium using Internet Explorer browser

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 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 which is language-independent, so that the browser can be controlled externally via any programming language of your choice.

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.

All IT Courses 50% Off

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.

Running Tests on Selenium using Internet Explorer browser

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.

Running Tests on Selenium using Internet Explorer browser

Step3: Extract the ZIP file, once the ZIP file download is complete.

Running Tests on Selenium using Internet Explorer browser

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

  1. The Zoom level should be set to 100%
  2. 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

Sometimes Selenium WebDriver users may fail to launch an IE driver using Selenium WebDriver. To overcome these common issues here are the solutions which most of the users might get faced.

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

Running Tests on Selenium using Internet Explorer browser

Step 3: Select Security Tab

Running Tests on Selenium using Internet Explorer browser

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).

Running Tests on Selenium using Internet Explorer browser

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)

Running Tests on Selenium using Internet Explorer browser

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%

Running Tests on Selenium using Internet Explorer browser

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:

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

  1. 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;

  }
Facebook Comments

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Related Articles

Back to top button