SUBSCRIBE HERE TO GET POST UPDATES VIA EMAIL :

Delivered by FeedBurner

How To Run Selenium WebDriver Test Script In Internet Explorer With Steps

Frequently we need to run selenium WebDriver test in different browsers like run selenium in internet explorer, Google Chrome, Opera, Mozilla Firefox etc.. for browser compatibility software testing. Selenium WebDriver software testing tool has separate driver for each browser. Selenium WebDriver has InternetExplorerDriver for IE browser. Earlier, I have already described HOW TO RUN WEBDRIVER TEST SCRIPT IN FIREFOX and HOW TO RUN TEST SCRIPT IN GOOGLE CHROME BROWSER. Now let's learn how to run WebDriver test In IE for software web application.

Configuration Steps To Run selenium Test In  internet explorer

Step 1 : Download IEDriverServer.exe
For running selenium internet explorer test, you need IEDriverServer.exe. You can download It from It from bellow given links.
  • Go to THIS PAGE and click on IEDriverServer.zip link.
Alternate download location
  • You can download It from THIS PAGE too as shown In bellow Image.

Save IEDriverServer.exe In your D: drive.

Step 2 : Configure IE Browser To Resolve Expected Errors
Before running your software automation selenium internet explorer test, You need to configure your IE browser to resolved bellow given 2 common errors which people are facing occasionally.

Error 1 : Exception in thread "main" 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 stacktrace information).

Error 2 : Exception in thread "main" org.openqa.selenium.remote.SessionNotFoundException: Unexpected error launching Internet Explorer. Browser zoom level was set to 200%. It should be set to 100% (WARNING: The server did not provide any stacktrace information).

Solution to resolve above errors Is as bellow.

Solution To Resolve Error 1 : Enable protected mode for all zones
You need to enable protected mode for all zones from Internet Options -> Security tab. To enable protected mode for all zones
  1. Open Internet Explorer browser.
  2. Go to menu Tools -> Internet Options.
  3. Click on Security tab.
  4. Select Internet from "Select a zone to view or change security settings" and Select(check) check box "Enable Protected Mode" from In the "Security level for this zone" block as shown In bellow Images.
  5. Apply same thing for all other 3 zones -> Local Internet, Trusted Sites and Restricted Sites as shown In bellow Images.

This setting will resolve error related to "Protected Mode settings are not the same for all zones."

Also you can resolve this error on run time. View THIS POST for detailed description and example.

Solution To Resolve Error 2 : Set IE browser zoom level to 100%
By default, IE browser's zoom level will be 100%. But If someone has changed It to 200% or any other level then you will face error during webdriver software test execution In IE browser and your test will fail. You need to set IE browser's zoom level 100%.

To Set IE browser's zoom level 100%
  1. Open Internet Explorer browser.
  2. Go to menu View -> Zoom -> Select 100% as shown In bellow Image.


This setting will resolve error related to "Browser zoom level was set to 200%. It should be set to 100%"

Also you can resolve this error on run time. View THIS POST for detailed description and example.

Step 3 : Execute First WebDriver Test In Internet Explorer browser
Now you are all set to execute first selenium webdriver In IE browser. I have created sample test to run test In IE browser. Execute bellow given sample calc test In eclipse and verify Its output In console.

IEBrowserSampleTest.java
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;

public class IEBrowserSampleTest {

 public static void main(String[] args) throws Exception {

  // Set path of IEDriverServer.exe.
  // Note : IEDriverServer.exe should be In D: drive.
  System.setProperty("webdriver.ie.driver", "D://IEDriverServer.exe");

  // Initialize InternetExplorerDriver Instance.
  WebDriver driver = new InternetExplorerDriver();

  // Load sample calc test URL.
  driver.get("http://only-testing-blog.blogspot.com/2014/04/calc.html");

  // Execute sample calc test.
  driver.findElement(By.xpath("//input[@id='1']")).click();
  driver.findElement(By.xpath("//input[@id='plus']")).click();
  driver.findElement(By.xpath("//input[@id='6']")).click();
  driver.findElement(By.xpath("//input[@id='equals']")).click();
  String result = driver.findElement(By.xpath("//input[@id='Resultbox']")).getAttribute("value");
  System.out.println("Calc test result Is : " + result);
  driver.close();
 }
}

At the end of execution, console output will be looks like bellow.


7 comments:

  1. It would be great help if you could explain why exception used and why we need to initiate the server for IE before creating the reference???

    ReplyDelete
    Replies
    1. System.setProperty("webdriver.ie.driver", "D://IEDriverServer.exe");

      >>The above command sets path of IE driver so that IE driver can be found and started.

      WebDriver driver = new InternetExplorerDriver();

      >>The above command starts and instance of IE driver. After instance is created, test scripts can be executed in the driver instance.

      It is only when the instance is created, we can execute our test scripts.

      Hope this discussion helps.

      Delete
    2. System.setProperty("webdriver.ie.driver", "D://IEDriverServer.exe");

      >>The above command sets path of IE driver so that IE driver can be found and started.

      WebDriver driver = new InternetExplorerDriver();

      >>The above command starts and instance of IE driver. After instance is created, test scripts can be executed in the driver instance.

      It is only when the instance is created, we can execute our test scripts.

      Hope this discussion helps.

      Delete
  2. Thanks for all your efforts. Keep going. :)

    ReplyDelete
  3. Complete content is not displayed in https pages and show all content pop-up is displayed and not able to proceed to next step.

    Can you please let me know to get through this problem?

    ReplyDelete
  4. Hi All,
    I am getting following issue while trying to execute test using testng.

    Can you please provide a solution to the following issue:

    Failed to load the library from temp directory: C:\Users\phillip\AppData\Local\Temp\IEDFDB8.tmpSep 15, 2016 9:31:01 PM org.openqa.selenium.os.UnixProcess checkForError
    SEVERE: org.apache.commons.exec.ExecuteException: Process exited with an error: 2 (Exit value: 2)

    Thanks a lot

    ReplyDelete
  5. Upon executing testng test with IE following issues appear:
    Can you please provide a solution to overcome this below issue.

    Failed to load the library from temp directory: C:\Users\Dillip\AppData\Local\Temp\IEDFDB8.tmpSep 15, 2016 9:31:01 PM org.openqa.selenium.os.UnixProcess checkForError
    SEVERE: org.apache.commons.exec.ExecuteException: Process exited with an error: 2 (Exit value: 2)

    ReplyDelete