Challenges faced with IE browser Selenium automation

Introduction

Developers and automation engineers face several challenges while automating tests on IE browser using Selenium WebDriver. On the other hand, such issues do not happen when working on other browsers like Chrome and Firefox. Hence, this article introduces you to those inherent issues of IE browser automation and how to resolve them. Also, we can browse through the different issues at Selenium official site which documents the problems faced by users.

Some of the typical issues faced during IE automation are :

  • The path to the driver executable must be set by the webdriver.ie.driver system property.
  • The browser’s zoom level is set to n%.
  • Protected Mode settings are not the same for all zones.
  • SendKeys works very slow it takes 1-2 second to type each character.

Challenges and Resolutions

Driver executable issue

The path to the driver executable must be set by the webdriver.ie.driver system property: This error throws java.lang.IllegalStateException. Like the error text says, it happens when IE driver is not located by Selenium script. To resolve it, you can set the path of Selenium Driver using System.setProperty method.

//Set the system property for IE driver
System.setProperty(“webdriver.ie.driver”,”C://path to//IEDriverServer.exe”);

If you are looking for detailed steps on how to download the driver and set the path, please refer to run the Selenium test with IE tutorial.

Zoom level issue

Browser zoom level was set to n%: It occurs when IE browsers zoom level is set to value other than 100%. Hence, it throws org.openqa.selenium.SessionNotCreatedException. Therefore, to resolve it set the zoom level of the browser to 100%. Go to tool > Zoom and select 100%.

After setting the zoom level to 100%, close the browser window and re-run the automation script.

Protected mode issue

Protected Mode settings are not the same for all zones: This error occurs when the security settings are different for different zones. Like above, it also throws the same org.openqa.selenium.SessionNotCreatedException exception. To resolve this error, please follow the steps demonstrated below:

  • Go to tools > Internet options and click.

  • It will open the Internet options window. Further, go to the security tab and select Internet. After that, click on the checkbox Enable protected mode.

  • Likewise, select the Enable Protected Mode checkbox for Local intranet, Trusted sites, and Restricted sites too for the different zones. And click on the Apply button.
  • Re-start the Internet Explorer. Next, when you re-run the script, the protected mode error will be resolved.

The slowness of Sendkey Issue

SendKeys works very slow it takes 1-2 second to type each character: This is also a frequent error in IE automation with 64-bit Windows driver. To resolve this error, we can replace the 64-bit driver executable with a 32-bit executable in the system. You can download 32-bit from here. Also, the 32-bit executable works well with 64-bit Windows as well. Consequently, replacing the 64-bit executable with 32 bit executable will resolve this exception. This error is registered in Selenium issue tracker here.

Untrusted SSL certificate

Untrusted SSL certificate error: IE browser is a secure browser. Therefore, it has stringent policies for maintaining security. One of the implications of stringent policies is that the IE browser shows SSL certificate error for websites starting with https when the site certificate is:

  • Not trusted.
  • Expired or not up to date.
  • Valid for only a particular site.

Please refer to the code sample below:

package seleniumAutomationTests;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;

public class MyFirstTest {

  public static void main(String[] args) {
    // TODO Auto-generated method stub
    
    //Set the system property for IE driver
    System.setProperty("webdriver.ie.driver","C:\\softwares\\drivers\\IEDriverServer.exe");
          
    //declare instance of WebDriver and run using IEdriver
    WebDriver driver = new InternetExplorerDriver();
        
    //load the webpage of application under test
    driver.get("https://untrusted-root.badssl.com/");
    
    //get the title of the page in a string variable
    String pageTitle = driver.getTitle();
    
    //print the page title on console
    System.out.println(pageTitle);
    
    //close the browser
    driver.close();

  }

}

When we try to access the web page in the code, it gives an SSL certificate error in Eclipse IDE. Hence, it does not load the webpage.

Therefore, instead of loading webpage, the browser also shows insecure connection error.

To get rid of the SSL certificate issue, the easiest method is to write below javascript code which handles the certificate error. Hence, lands the automation script on the webpage under test.

driver.navigate().to(“javascript:document.getElementById(‘overridelink’).click()”);

Please refer to the code snippet below:

package seleniumAutomationTests;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;

public class MyFirstTest {

  public static void main(String[] args) {
    // TODO Auto-generated method stub
    
    //Set the system property for IE driver
    System.setProperty("webdriver.ie.driver","C:\\softwares\\drivers\\IEDriverServer.exe");
          
    //declare instance of WebDriver and run using IEdriver
    WebDriver driver = new InternetExplorerDriver();
        
    //load the webpage of application under test
    driver.get("https://untrusted-root.badssl.com/");
    driver.navigate().to("javascript:document.getElementById('overridelink').click()"); 
    
    //get the title of the page in a string variable
    String pageTitle = driver.getTitle();
    
    //print the page title on console
    System.out.println(pageTitle);
    
    //close the browser
    driver.close();

  }

}

Conclusion

In this tutorial, we saw some of the common issues which developers face while writing Selenium automation code for IE browser and their corresponding resolutions. In the next tutorial, we will learn about Internet Driver Server which forms the link between Selenium IE browser tests and browser.

Translate ยป