Overcoming Challenges In Selenium Testing On Internet Explorer

Overcoming Challenges In Selenium Testing On Internet Explorer

Selenium testing on Internet Explorer online presents unique challenges. This blog offers effective solutions to overcome these challenges and ensure reliable test automation on the IE browser. From configuring system properties and environment variables to addressing browser zoom levels and SendKeys slowness, each challenge is addressed with practical steps and insights to enhance Selenium testing effectiveness. 

In this article, we will learn about the strategies to overcome challenges in Selenium Testing on Internet Explorer. 

Challenges in Selenium Testing on Internet Explorer

Let us see various obstacles faced during Selenium testing on Internet Explorer online and provide practical insights and strategies to overcome them effectively.

Path to IE Driver

The first issue anybody would face with the IE Browser is that people expect the IE Browser to work exactly like the Firefox Browser in Selenium. See what happens when you use the Selenium Script below to open an application on the IE browser.

// Change the package name accordingly, as per your project
package selenium;
import org.openqa.selenium.ie.InternetExplorerDriver;

public class IEExplorerTest {
    public static void main(String[] args) {
        InternetExplorerDriver  driver = new InternetExplorerDriver();
        driver.get(“https://demoqa.com”);
    }
}

If you get “java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.ie.driver system property,” it means Selenium needs the IEDriverServer.exe path via “webdriver.ie.driver.” This happens if the file is missing or not in the PATH variable.

How to Set the System Property for IE Browser in Selenium Script?

I hope you have gone through the chapter of Running Test in IE Explorer and know how to download & from where to download IEDriverServer exe.

Selenium Script would look like this

// Change the package name accordingly, as per your project
package selenium;

public class IEExplorerTest {
    public static void main(String[] args) {
        // Path to the folder where you have extracted the IEDriverServer executable
        String service = “D:\\ToolsQA\\trunk\\Library\\drivers\\IEDriverServer.exe”;
        System.setProperty(“webdriver.ie.driver”, service);

        InternetExplorerDriver  driver = new InternetExplorerDriver();
        driver.get(“https://demoqa.com”);
    }
}

How to Set the Path Environment Variable for IE Browser?

Open the Control Panel -> System or Security –> System; the same thing can be done by right-clicking on ‘MyComputer’ and choosing Properties.

  1. Choose ‘Advanced system settings’.
  2. Under the Advanced tab, Choose the ‘Environment Variable…’ option.
  3. Now, we need to specify the location in the PATH variable. For PATH, it most probably already exists on your machine. So just select it and choose the Edit option.
  4. In the editor, add the value ‘Your Location of IE Browser’ and click OK.
// Change the package name accordingly, as per your project
package selenium;
public class IEExplorerTest {
    public static void main(String[] args) {
        InternetExplorerDriver  driver = new InternetExplorerDriver();
        driver.get(“https://demoqa.com”);
    }
}

Protected Mode Settings

Internet Explorer’s Protected Mode settings can pose challenges for Selenium testing when inconsistent across different zones. Testers may face exceptions related to Protected Mode settings, which show they must be the same for all zones. Testers should navigate to Internet Options in Internet Explorer online and ensure that the Enable Protected Mode option is set consistently across all zones to resolve this issue.

First, look at the code to open an Internet Explorer online driver using Selenium WebDriver Script.

package selenium;

public class IEExplorerTest {

    public static void main(String[] args) {
        //Path to the folder where you have extracted the IEDriverServer executable
        String service = “D:\\ToolsQA\\trunk\\Library\\drivers\\IEDriverServer.exe”;
        System.setProperty(“webdriver.ie.driver”, service);

        InternetExplorerDriver  driver = new InternetExplorerDriver();
        driver.get(“https://demoqa.com”);
    }
}

Selenium might face a problem when you run the code and stop unexpectedly. This specific exception, “SessionNotFoundException, ” indicates a problem launching Internet Explorer online.

The above error clearly says there is some issue with the Protected Mode Settings, which are not the same for all the zones. To avoid this error, we must set the Protected Mode Settings to the same for all the Zones.

How to set the Protected Mode settings in IE Browser?

  1. Go to Tools > Internet Options, and Under Internet Options, click on the Security tab.
  2. Click on the Internet zone to select a zone and view its Protected Mode property.
  3. Now check the Enable Protected Mode checkbox. Whichever one you choose needs to be set for all the other zones. This means it can be either OFF for all the zones or ON for all the zones.

Repeat this task for all the zones

  • Internet
  • Local Intranet
  • Trusted Sites
  • Restricted Sites

Click OK and run the Selenium script again. It will work this time.

Browser Zoom Level

The different zoom levels of browsers may cause unexpected errors in the Selenium testing on Internet Explorer online. Testers may encounter problems such as being zoomed in at the browser with an incorrect value other than 100%. This would make scripts to fail. The testers must confirm that the zoom level in the browser is 100% to remove this problem through the browser settings. This maintains order and avoids browser zoom-level mismatch-related errors.

If your application is not starting or you are facing the error message “org.openqa.selenium.remote.SessionNotFoundException: IE Error: unexpected launch. Browser zoom level was set to 125%. It should be set to 100%,” the problem is, probably, IE browser’s zoom level has been set up to 125% when it must be 100%.

To fix this problem, check that Internet Explorers Zoom property is 100 %. The altering of the zoom level on your web browser can achieve these. You ensure that the browser’s display is consistent and compatible with Selenium testing by setting the zoom level to 100%.

SendKeys Slowness

Testers may notice that SendKeys operations are slower when running Selenium scripts on Internet Explorer online than other browsers. This slowness can impact the efficiency of test execution and overall productivity. Testers can improve SendKeys’ performance by using the 32-bit version of IEDriverServer.exe. Testers can experience faster SendKeys operation and smoother test execution by replacing the existing IEDriverServer.exe with the 32-bit version.

Addressing SendKeys slowness on Internet Explorer online involves some steps.

  1. Download the 32-bit version of IEDriverServer.exe, even if your system is 64-bit.
  2. Extract the downloaded zip file and locate the IEDriverServer executable.
  3. Replace the existing IEDriverServer.exe in your Selenium project directory with the 32-bit version.
  4. Run your Selenium script again, and you should observe improved performance with SendKeys operation on Internet Explorer online.

By following these steps and utilizing the 32-bit version of IEDriverServer.exe, testers can overcome the slowness associated with SendKeys on Internet Explorer online to ensure smoother test execution comparable to other browsers like Chrome and Firefox.

Untrusted SSL Certificate

Handling untrusted SSL certificates is another challenge Selenium testers face on Internet Explorer online. Testers may encounter SSL certificate errors that prevent scripts from proceeding, impacting the reliability of test automation. 

To overcome this challenge, testers can either navigate to the URL using JavaScript to bypass certificate errors or set DesiredCapabilities to accept SSL certificates. This ensures that Selenium scripts can proceed without being blocked by SSL certificate warnings, ensuring uninterrupted test execution.

As a Microsoft product, Internet Explorer prioritizes security, often leading to SSL certificate pop-ups when used with Selenium. To address this issue, testers can employ one of two solutions:

Add the script below just under the code to open the application

// Change the package name accordingly, as per your project
package selenium;

public class IEExplorerTest {

    public static void main(String[] args) {
        //Path to the folder where you have extracted the IEDriverServer executable
        String service = “D:\\ToolsQA\\trunk\\Library\\drivers\\IEDriverServer.exe”;
        System.setProperty(“webdriver.ie.driver”, service);

        InternetExplorerDriver  driver = new InternetExplorerDriver();
        driver.get(“URL for which certificate error is coming”);
        driver.navigate().to(“javascript:document.getElementById(‘overridelink’).click()”); 
    }
}

Another way of avoiding this error is to use the DesiredCapability settings of the browser.

// Change the package name accordingly, as per your project
package selenium;

public class IEExplorerTest {

    public static void main(String[] args) {
        // Path to the folder where you have extracted the IEDriverServer executable
        String service = “D:\\ToolsQA\\trunk\\Library\\drivers\\IEDriverServer.exe”;
        System.setProperty(“webdriver.ie.driver”, service);

        // Create the DesiredCapability object of InternetExplorer
        DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer();

        // Settings to Accept the SSL Certificate in the Capability object
        capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);

        InternetExplorerDriver driver = new InternetExplorerDriver(capabilities);
        driver.get(“URL for which certificate error is coming”);
    }
}

After putting the above code, run your script. No SSL Certificate Error will appear on the screen this time, and the script will run fine. These solutions ensure that SSL certificate errors do not hinder Selenium testing on Internet Explorer, promoting seamless automation.

Element Identification Issues

Element identification can be inconsistent or problematic in Internet Explorer online due to differences in the DOM or rendering compared to other browsers. This can lead to script failures or unreliable test results.

To address element identification issues:

  • Prefer using XPath or CSS selectors over other locators like ID or class as they tend to be more stable across browsers.
  • Avoid using absolute XPath, as it can be brittle and prone to breaking with DOM changes. Instead, construct XPath expressions relative to the nearest stable parent element.
  • Use explicit waits to ensure elements are fully loaded and visible before interacting to reduce element-not-found errors.

Compatibility Mode

Internet Explorer online may render pages in compatibility mode, emulating older browser versions, which can affect page layout and functionality.

To handle compatibility mode

  • Set the document mode to the latest IE version with a meta tag or X-UA-Compatible header. 
  • Test your app in different modes to catch and fix compatibility issues.

Handling JavaScript Errors

JavaScript errors in the application can interfere with Selenium test execution on Internet Explorer, leading to unexpected failures or behavior.

To manage JavaScript errors

  • Configure Internet Explorer to suppress JavaScript error dialogs during test execution to prevent interruptions. This can be achieved through browser settings or registry modifications.
  • Implement logging mechanisms to capture JavaScript errors reported in the browser console during test execution.

Performance Optimization:

Internet Explorer may perform slower than other browsers, impacting test execution speed and efficiency.

To optimize performance

  • Reduce the frequency and complexity of DOM manipulation operations in Selenium scripts to improve performance on Internet Explorer.
  • Review and optimize CSS and JavaScript code in the application to enhance rendering and execution speed in Internet Explorer.
  • Distribute test cases across multiple instances of Internet Explorer to use parallel execution and reduce overall test execution time.
  • To optimize performance, cloud platforms for Selenium testing on Internet Explorer should be incorporated to utilize scalable infrastructure and distributed cloud testing capabilities. One such platform is LambdaTest. LambdaTest is an AI-powered test orchestration and execution platform to run manual and automated tests at scale. The platform allows you to perform both real-time and automation testing across 3000+ environments and real mobile devices.

Conclusion

In conclusion, By implementing the strategies in this blog, testers can navigate the intricacies of Selenium testing on Internet Explorer. These solutions support testers to overcome challenges and improve their automation efforts to enhance productivity and reliability in Selenium testing on the IE browser.