Use Internet Explorer Driver to automate IE mode in Microsoft Edge

If you have business-critical legacy websites or apps, you may need to test your content in Internet Explorer (IE) mode in Microsoft Edge. This article describes how to get started with Internet Explorer Driver (IEDriver) to automate IE mode in Microsoft Edge.

IE mode in Microsoft Edge is a feature for organizations that still need Internet Explorer 11 for backward compatibility for legacy websites or apps. To learn more about IE mode, read What is Internet Explorer (IE) mode?

Starting June 15, 2022, Internet Explorer 11 will no longer be supported on certain versions of Windows 10. For more information, read Internet Explorer 11 desktop app retirement FAQ.

Download Internet Explorer Driver (IEDriver)

To begin automating tests in IE mode in Microsoft Edge, download IEDriver. Make sure that the version of IEDriver that you download is 4.0.0.0 or greater.

The IEDriver section of the Downloads page for Selenium

Required Configuration

To configure IEDriver, Windows, and Microsoft Edge correctly, complete the requirements for Selenium's required configuration.

Place the driver executable in the PATH

The driver executable needs to be placed in the PATH; see IE Driver Server. The top of that page reads: "The standalone server executable must be downloaded from the Downloads page and placed in your PATH."

If the driver location isn't included in the PATH, you must set the driver location using the Java system property webdriver.ie.driver or some other way.

Automate IE mode in Microsoft Edge

The following sections walk you through using Selenium to automate IE mode in Microsoft Edge.

This article provides instructions for using the Selenium framework, but you can use any library, framework, and programming language that supports WebDriver. To accomplish the same tasks using another framework, consult the documentation for your framework of choice.

To launch Microsoft Edge in IE mode with IEDriver:

  1. Define InternetExplorerOptions with additional properties that point to the Microsoft Edge browser.

  2. Start an instance of InternetExplorerDriver and pass it InternetExplorerOptions. IEDriver launches Microsoft Edge and then loads your web content in IE mode.

The next section shows the complete sample, and then the subsequent sections focus on each of the main steps that are listed above.

The complete sample

The following sample launches Microsoft Edge in IE mode, navigates to bing.com, and then searches for "WebDriver".

using System;
using OpenQA.Selenium;
using OpenQA.Selenium.IE;

namespace IEDriverSample
{
    class Program
    {
        static void Main(string[] args)
        {
            var ieOptions = new InternetExplorerOptions();
            ieOptions.AttachToEdgeChrome = true;
            //change the path accordingly
            ieOptions.EdgeExecutablePath = "C:/Program Files (x86)/Microsoft/Edge/Application/msedge.exe";

            var driver = new InternetExplorerDriver(ieOptions);
            driver.Url = "https://bing.com";
            driver.FindElement(By.Id("sb_form_q")).SendKeys("WebDriver");
            driver.FindElement(By.Id("sb_form")).Submit();

            driver.Quit();
        }
    }
}

The following sections explain the steps in this sample in more detail.

Define InternetExplorerOptions with additional properties for Microsoft Edge

Define InternetExplorerOptions with additional properties that point to the Microsoft Edge browser.

  1. Define a new variable, ieOptions, by calling InternetExplorerOptions().

  2. Set ieOptions.AttachToEdgeChrome property to true, and ieOptions.EdgeExecutablePath to the path of the Microsoft Edge executable.

var ieOptions = new InternetExplorerOptions();
ieOptions.AttachToEdgeChrome = true;
//change the path accordingly
ieOptions.EdgeExecutablePath = "C:/Program Files (x86)/Microsoft/Edge/Application/msedge.exe";

Start IEDriver

Start IEDriver. IEDriver launches Microsoft Edge and then loads your web content in IE mode.

Start InternetExplorerDriver and pass it the previously defined ieOptions. IEDriver launches Microsoft Edge in IE mode. All page navigation and subsequent interactions occur in IE mode.

var driver = new InternetExplorerDriver(ieOptions);

Known limitations

This section covers known scenarios that previously worked with IEDriver and the IE11 desktop application but require workarounds when using IEDriver with Microsoft Edge in IE mode.

Opening new windows

If your test code creates a new browser window using one of the following methods, you may need to add a short wait operation afterwards to ensure that IEDriver has detected the new window:

  • Opening a new window by calling window.open from <script> in the page.
  • Opening a new window by using the WebDriver New Window command.

To ensure the new window has been created successfully and IEDriver has detected it, you must continuously check the result of the Get Window Handles command until it contains a handle to the new window.

The following sample demonstrates a possible way to wait for new window handles to be detected when opening new windows.

After the Click method is called on a button that opens a new window, the test code must wait until driver.WindowHandles contains the new window handle.

var initialHandleCount = driver.WindowHandles.Count;
driver.FindElement(By.Id("<Id of the button that will open a new window>")).Click();
var newHandles = driver.WindowHandles;
while (newHandles.Count == initialHandleCount)
{
    newHandles = driver.WindowHandles;
}

Creating and switching between tabs

If your test code switches between multiple tabs in the same Microsoft Edge window, tabs that become inactive may not be included in the list of handles returned by Get Window Handles. In the Internet Explorer 11 desktop application, IEDriver will return handles for all of the tabs in IE, regardless of activation state.

When using Microsoft Edge in IE mode, if your test switches focus away from a certain tab and you would like to be able to switch back to that tab later, you must store a copy of the tab's window handle.

See also