How to Run Selenium Test on IE (Internet Explorer)?

We offer you a brighter future with FREE online courses - Start Now!!

Selenium is a popular automation testing tool used to automate web applications. It supports various web browsers, including Google Chrome, Mozilla Firefox, Safari, and Microsoft Edge. In this article, we will discuss how to run Selenium tests on Internet Explorer (IE).

Internet Explorer is one of the oldest web browsers and has been the default browser in Windows operating systems for a long time. Although it has been replaced by Microsoft Edge as the default browser, IE is still used by many organizations, especially in enterprise environments.

Before we begin, let’s understand the prerequisites to run Selenium tests on Internet Explorer.

Prerequisites to run Selenium Tests on IE:

1. Selenium WebDriver:

Selenium WebDriver is the primary component of the Selenium toolset. It is a programming interface that allows us to interact with web browsers programmatically. We can write scripts in various programming languages such as Java, Python, C#, etc., using Selenium WebDriver.

2. Internet Explorer Driver:

Internet Explorer Driver is a separate executable that WebDriver uses to control IE. It acts as a bridge between the Selenium script and the IE browser. We need to download and install the Internet Explorer Driver separately.

3. Internet Explorer Browser:

Obviously, we need to have the Internet Explorer browser installed on our system. Also, we need to make sure that the browser version matches with the version of the Internet Explorer Driver we are using.

Now that we have the prerequisites installed let’s see how we can run Selenium tests on Internet Explorer.

Step 1: Download and Install Internet Explorer Driver

First, we need to download the Internet Explorer Driver executable from the official Selenium website. Select the version that matches the version of the IE browser installed on your system.

After downloading the driver executable, extract the contents of the ZIP file to a folder on your system.

Step 2: Configure Internet Explorer

Before we start running Selenium tests on IE, we need to configure the browser settings. Follow the steps below to configure Internet Explorer:

a. Go to the Tools menu in Internet Explorer once it is open.

b. Click on Internet Options.

c. Under the Security tab of the Internet Options box, click.

d. Click on the Custom level button after selecting the Internet zone.

e. Scroll down to the Scripting section and enable the following options:

  • Active scripting
  • Allow Programmatic clipboard access
  • Allow status bar updates via script
  • Scripted windows can be used to ask for information on websites.

f. Click on the OK button to save the changes.

Step 3: Create a Selenium Project

To create a Selenium project, we need to follow the steps below:

a. Launch the Eclipse IDE, then start a new Java project.

b. Right-click on the project and select Properties.

c. In the Properties window, select Java Build Path from the left-hand menu.

d. After selecting the Library tab, press the Add External JARs button.

e. Browse to the folder where you extracted the Internet Explorer Driver executable and select the “IEDriverServer.exe” file.

f. Click on the OK button to add the JAR file to the project.

Step 4: Write a Selenium Test Script

Now that we have created the project and configured the Internet Explorer browser let’s write a simple Selenium test script to launch IE and navigate to a website.

a. Open Eclipse IDE and create a new Java class.

b. Add the following code to the class:

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

public class IETest {

public static void main(String[] args) {

// Set the path of the Internet Explorer Driver executable
System.setProperty("webdriver.ie.driver", "C:\\Selenium\\IEDriverServer.exe");

// Create an instance of InternetExplorerDriver
WebDriver driver = new InternetExplorerDriver();

// Navigate to a website
driver.get("https://www.example.com");

// Close the browser
driver.quit();
}
}

In the above code, we have imported the WebDriver and InternetExplorerDriver classes from the Selenium library. We have set the path of the Internet Explorer Driver executable using the `System.setProperty()` method. Then we have created an instance of the `InternetExplorerDriver` class, which launches the IE browser. We have navigated to a website using the `get()` method of the WebDriver interface. Finally, we have closed the browser using the `quit()` method of the WebDriver interface.

Step 5: Run the Selenium Test

To run the Selenium test, follow the steps below:

a. Right-click on the IETest class and select Run As > Java Application.

b. Eclipse will compile the code and launch Internet Explorer.

c. Internet Explorer will navigate to the website specified in the script.

d. Once the test is complete, the browser will close automatically.

If the test runs successfully, you should see Internet Explorer launching and navigating to the specified website.

Tips and Best Practices to run Selenium Tests in IE

1. Always make sure that the Internet Explorer browser version matches with the version of the Internet Explorer Driver you are using. Otherwise, you may face compatibility issues.

2. Use the latest version of the Internet Explorer Driver available on the Selenium website to ensure maximum compatibility.

3. Before running the Selenium test on Internet Explorer, make sure that no other instances of IE are running on the system.

4. If you face any issues while running the test, try restarting the Internet Explorer browser or your system.

Conclusion

In this article, we have discussed how to run Selenium tests on Internet Explorer. We have seen the prerequisites, configuration steps, and code required to run a simple Selenium test on IE. Although Internet Explorer is an old browser, it is still widely used in enterprise environments, and Selenium supports it. With the steps and best practices mentioned in this article, you should be able to run Selenium tests on Internet Explorer with ease.

Your 15 seconds will encourage us to work even harder
Please share your happy experience on Google

follow dataflair on YouTube

Leave a Reply

Your email address will not be published. Required fields are marked *