Working with Internet Explorer

As we already discussed how Selenium works with Firefox and Chrome browser, we will be focusing on the interaction of Selenium WebDriver with Internet Explorer browser. Just to recollect WebDriver has an inbuilt support for Firefox, no additional driver is  required. Chrome browser requires Chrome Driver and we need to set a system property for the same. To learn more about Chrome Driver visit Working with Chrome.

WebDriver interacts in a similar way with IE browser as it interacts with Chrome. So talking about similarity IE also requires Internet Explorer driver like we had Chrome driver for Chrome browser.

Setting up Environment for IE:

  • Go to Selenium’s official site i.e. http://www.seleniumhq.org/download
  • Under “The Internet Explorer Driver Server” section we can download IE driver as per our system requirement.It comes as 32 bit Windows IE and 64 bit Windows IE. Refer this for better clarity:
  • Click on 32 bit Windows IE or 64 bit Windows IE as per your Operating System.
  • Extract the zip file.
  • Set the value of a System variable with the path of its driver location.
System.setProperty("webdriver.ie.driver", "path of IE driver on local machine");

setProperty() method accepts two String arguments. the first one is a variable name (here, IE driver name i.e. webdriver.ie.driver) and second is its value (here, the location of IE driver on your local machine e.g. C:\Users\dell\Downloads\IEDriverServer.exe).

Challenges faced with IE Driver:

Till now the steps we followed were correct but still on invoking browser we will be getting error on console screen saying :

org.openqa.selenium.remote.SessionNotFoundException: Unexpected error launching Internet Explorer. Protected Mode settings are not the same for all zones. Enable Protected Mode must be set to the same value (enabled or disabled) for all zones. (WARNING: The server did not provide any stack trace information)Command duration or timeout: 516 milliseconds

Addition configurations required for IE:

Just downloading IE driver and setting system property in case of IE browser doesn’t help. Additionally, we have to make some setting in our browser.Follow these steps-

  1. Go to IE Browser
  2. Tools menu ->Internet Options in tools menu->Security tab
  3. Select Enable Protected Mode option -> Check the default Zone level for “Internet”. If you look at the screenshot below, security level for this zone is selected as “Allowed level for this zone ” “Medium to High” and “Enable Protected Mode” option is Checked

Challenges faced with IE Driver

  1. Likewise, for Local Intranet and Trusted sites we will keep same settings i.e. Enable protected mode Checked and Security level for zones set to Medium-high as per above example.Security level for zone could be set as High,Medium etc. but then it needs to be same for the Internet,Local Intranet, and Trusted sites.
  2. Restricted sites “Enable Protection mode” is checked by default and we can need to leave it as it is. No settings required for it.

All other code lines and basic API’s remain same like that of Internet Explorer like Firefox and Chrome browser.

package com.qatechhub.day1;

import org.openqa.selenium.ie.InternetExplorerDriver;

public class WorkingWithInternetExplorer {

	InternetExplorerDriver ieDriver;

	String url = "http://www.qatechhub.com";

	public void invokeBrowser(){
		/*Setting property of a system variable used by Internet Explorer Driver*/
		System.setProperty("webDriver.ie.driver", "C:\\workspace\\libs\\IEDriverServer.exe");

		ieDriver = new InternetExplorerDriver();

		/* To Maximize the window */
		ieDriver.manage().window().maximize();

		/* To delete all the cookies of the browser */
		ieDriver.manage().deleteAllCookies();

		/* To navigate to a particular URL */
		ieDriver.get(url);

		String titleOfPage;

		/* To get The Title of the page */

		titleOfPage = ieDriver.getTitle();

		System.out.println("Title of the page is : " + titleOfPage);

		String currentUrl;

		/* To get The url of the page */
		currentUrl = ieDriver.getCurrentUrl();

		System.err.println("Title of the page is : "+ currentUrl);

		String pageSource;

		/* To get The source code current page */
		pageSource = ieDriver.getPageSource();
		System.out.println("Page Source : "+ pageSource);
	}
	public void closeBrowser(){
		/* To close current active window of the browser */
		ieDriver.close();
	}

	public void closeAllBrowser(){

		/* To close all the opened browser session*/
		ieDriver.quit();
	}

}

To go through all the API’s visit Working with Firefox.

For any questions, query or feedback. Feel free to write us at amrita@qatechhub.com or support@qatechhub.com. 

Happy Learning 🙂

Saurabh Dhingra

About the Author

Saurabh Dhingra

Follow Saurabh Dhingra: