How to run test cases using Internet Explorer in selenium automation script

It is very easy to run test cases using Internet Explorer in selenium webdriver. You can not launch Internet Explorer directly in java but you can use selenium IE Driver server to communicate with it instead. So what selenium IE Driver server is and how to use it?

What is selenium IE Driver server?

Although there is not any native Internet Explorer implementation in selenium webdriver, but selenium webdriver commands should be directed to Internet Explorer by IEDriver server. It is just a bridge between your selenium commands and browser. It is implemented in a windows executable file. You should download it first and then add it to your system path before using it.

Goto following page to download the latest version.
http://selenium-release.storage.googleapis.com/index.html.

I just download IEDriverServer_x64_3.4.0.zip because my OS is windows 64 bit OS.

After download, extract it to a local directory. I extract it to C:\Workspace\dev2qa.com\Lib\IEDriverServer_x64_3.4.0

Launch Internet Explorer using selenium webdriver

Method 1: Set system property “webdriver.ie.driver”‘s value to IE Driver executable file path.

It is very easy to create and use Internet Explorer in selenium webdriver. You just need to specify the IE Driver executable file path in system property “webdriver.ie.driver” and then use InternetExplorerDriver to initiate and manage Internet Explorer like following.

 String ieDriverFilePath = "C:\\Workspace\\dev2qa.com\\Lib\\IEDriverServer_x64_3.4.0\\IEDriverServer.exe";
 //Specify the executable file path to sysem property.
 System.setProperty("webdriver.ie.driver", ieDriverFilePath);
 //Initiate web browser
 InternetExplorerDriver ieDriver = new InternetExplorerDriver();
 ieDriver.get("http://www.dev2qa.com");

You should make your Internet Explorer’s “Protected Mode Settings” same value to all zones before running the code above. Otherwise you may encounter exceptions.

Change “Protected Mode settings” to same value in IE

  1. Open your Internet Explorer Click tools —> Internet Options
    IE9-tools-options
  2. Click Security tab, check Enable Protected Mode checkbox for all zones.
    enable protected mode for all zones in internet options
  3. Click OK.
READ :   Selenium WebDriver - Handle Keyboard And Mouse Events

Method 2: Use IE Driver service builder

Another way to run Internet Explorer in selenium webdriver is to use IE Driver service builder. You can specify IEDriver executable file path to the service builder instead of system property. You can set log file also, with log file you can debug any issue easily.

 String ieDriverFilePath = "C:\\Workspace\\dev2qa.com\\Lib\\IEDriverServer_x64_3.4.0\\IEDriverServer.exe";
 //Create server service builder
 InternetExplorerDriverService.Builder ieDriverServiceBuilder = new InternetExplorerDriverService.Builder();
 //Start sever on any free and available port.
 ieDriverServiceBuilder.usingAnyFreePort();
 //Specify IEDriver executable file.
 ieDriverServiceBuilder.usingDriverExecutable(new File(ieDriverFilePath));
 //Specifies log level
 ieDriverServiceBuilder.withLogLevel(InternetExplorerDriverLogLevel.TRACE);
 //Specify where log file stored.
 ieDriverServiceBuilder.withLogFile(new File("C:\\Workspace\\dev2qa.com\\logFile.txt"));
 //Initiate a service
 InternetExplorerDriverService service = ieDriverServiceBuilder.build();
 //Use service object to initiate IEDriver instance
 InternetExplorerDriver ieDriver = new InternetExplorerDriver(service);
 ieDriver.get("http://www.dev2qa.com");

More about selenium IE Driver Server

Now you have known how to start and communicate with IEDriver server in selenium webdriver. But you can also start it as a standalone, waiting for commands coming from your webdriver actions and pass those commands to Internet Explorer. Webdriver actions include Webdriver.findElement, Webdriver.get etc.

You can start IEDriver server simply by type “IEDriverServer.exe” in your extracted directory in dos window as following.
start ie driver server standalone

If you add -help to IEDriverServer.exe, it will list all parameters and description that can by applied to it.
help for IEDriver server

How to start IE Driver server with different port number

If you want to start it with a port other than default port number you can input command with port parameter as following.
IEDriverServer.exe /port=8088

You can also specify log file path and log level with parameter.
IEDriverServer.exe /log-file=C:\\Workspace\\dev2qa.com\\ieDriverLog.txt /port=8088 /log-level=DEBUG
ie driver server with more parameters

How to connect to existing IE Driver server

Now the standalone IE Driver server is running. You can connect to it in your java code simply by specify the server ip and port number.

 //Set IEDriverServer port number.
 ieDriverServiceBuilder.usingPort(8088);
//Specify executable file path.
 ieDriverServiceBuilder.usingDriverExecutable(new File(ieDriverFilePath));
//Set IEDriver server host ip.
 ieDriverServiceBuilder.withHost("localhost");

Download “TestWithInternetExplorer.zip” TestWithInternetExplorer.zip – Downloaded 54 times – 986 B

(Visited 515 times, 1 visits today)

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.