| title | Use Internet Explorer Driver to automate IE mode in Microsoft Edge |
|---|---|
| description | How to test your legacy website or app in IE mode in Microsoft Edge. |
| author | MSEdgeTeam |
| ms.author | msedgedevrel |
| ms.topic | article |
| ms.service | microsoft-edge |
| ms.subservice | devtools |
| ms.date | 11/23/2021 |
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.
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.
To configure IEDriver, Windows, and Microsoft Edge correctly, complete the requirements for Selenium's required configuration.
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.
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:
-
Define
InternetExplorerOptionswith additional properties that point to the Microsoft Edge browser. -
Start an instance of
InternetExplorerDriverand pass itInternetExplorerOptions. 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 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();
}
}
}from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
ie_options = webdriver.IeOptions()
ie_options.attach_to_edge_chrome = True
ie_options.edge_executable_path = "C:/Program Files (x86)/Microsoft/Edge/Application/msedge.exe"
driver = webdriver.Ie(options=ie_options)
driver.get("http://www.bing.com")
elem = driver.find_element(By.ID, 'sb_form_q')
elem.send_keys('WebDriver' + Keys.RETURN)
driver.quit()import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.ie.InternetExplorerOptions;
public class IEDriverSample {
public static void main(String[] args) {
InternetExplorerOptions ieOptions = new InternetExplorerOptions();
ieOptions.attachToEdgeChrome();
ieOptions.withEdgeExecutablePath("C:\\Program Files (x86)\\Microsoft\\Edge\\Application\\msedge.exe");
WebDriver driver = new InternetExplorerDriver(ieOptions);
driver.get("http://www.bing.com");
WebElement elem = driver.findElement(By.id("sb_form_q"));
elem.sendKeys("WebDriver", Keys.RETURN);
driver.close();
}
}const {Builder, By, Key, until} = require('selenium-webdriver');
const {Options} = require('selenium-webdriver/ie');
(async () => {
let ieOptions = new Options();
ieOptions.setEdgeChromium(true);
ieOptions.setEdgePath('C:/Program Files (x86)/Microsoft/Edge/Application/msedge.exe');
let driver = await new Builder().
forBrowser('ie').
setIeOptions(ieOptions).
build();
try {
await driver.get('http://www.bing.com');
let elem = await driver.findElement(By.id('sb_form_q'));
await elem.sendKeys('WebDriver', Key.RETURN);
await driver.wait(until.titleIs('WebDriver - Bing'), 1000);
} finally {
await driver.quit();
}
})();The following sections explain the steps in this sample in more detail.
Define InternetExplorerOptions with additional properties that point to the Microsoft Edge browser.
-
Define a new variable,
ieOptions, by callingInternetExplorerOptions(). -
Set
ieOptions.AttachToEdgeChromeproperty totrue, andieOptions.EdgeExecutablePathto 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";-
Define a new variable,
ie_options, by callingwebdriver.IeOptions(). -
Set the
ie_options.attach_to_edge_chromeproperty toTrue, andie_options.edge_executable_pathto the path of the Microsoft Edge executable.
ie_options = webdriver.IeOptions()
ie_options.attach_to_edge_chrome = True
ie_options.edge_executable_path = "C:/Program Files (x86)/Microsoft/Edge/Application/msedge.exe"-
Define a new variable
ieOptionsof typeInternetExplorerOptions, by callingnew InternetExplorerOptions(). -
Call
ieOptions.attachToEdgeChrome()andieOptions.withEdgeExecutablePath()with the path of the Microsoft Edge executable.
InternetExplorerOptions ieOptions = new InternetExplorerOptions();
ieOptions.attachToEdgeChrome();
ieOptions.withEdgeExecutablePath("C:\\Program Files (x86)\\Microsoft\\Edge\\Application\\msedge.exe");-
Define a new variable,
ieOptions, by callingOptions(). -
Call
ieOptions.setEdgeChromium()with valuetrueandieOptions.setEdgePath()with the path of the Microsoft Edge executable.
let ieOptions = new Options();
ieOptions.setEdgeChromium(true);
ieOptions.setEdgePath('C:/Program Files (x86)/Microsoft/Edge/Application/msedge.exe');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);Start IEDriver by calling webdriver.Ie and passing it the previously defined ie_options. IEDriver launches Microsoft Edge in IE mode. All page navigation and subsequent interactions occur in IE mode.
driver = webdriver.Ie(options=ie_options)Start IEDriver by calling new InternetExplorerDriver() and passing it the previously defined ieOptions. IEDriver launches Microsoft Edge in IE mode. All page navigation and subsequent interactions occur in IE mode.
WebDriver driver = new InternetExplorerDriver(ieOptions);Start IEDriver by calling Builder.forBrowser('ie') and setIeoptions(ieOptions). IEDriver launches Microsoft Edge in IE mode. All page navigation and subsequent interactions occur in IE mode.
let driver = await new Builder().
forBrowser('ie').
setIeOptions(ieOptions).
build();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.
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;
}After the click method is called on a button that opens a new window, the test code must wait until driver.window_handles contains the new window handle.
initial_handle_count = len(driver.window_handles)
driver.find_element(By.ID, "<Id of the button that will open a new window>").click()
new_handles = driver.window_handles
while len(new_handles) == initial_handle_count:
new_handles = driver.window_handlesAfter the click method is called on a button that opens a new window, the test code must wait until driver.getWindowHandles() contains the new window handle.
int initialHandleCount = driver.getWindowHandles().size();
driver.findElement(By.id("<Id of the button that will open a new window>")).click();
Set<String> newHandles = driver.getWindowHandles();
while (newHandles.size() == initialHandleCount) {
newHandles = driver.getWindowHandles();
}After the click method is called on a button that opens a new window, IEDriver must wait with await driver.getAllWindowHandles().
const initialHandleCount = (await driver.getAllWindowHandles()).length;
const elem = await driver.findElement(By.id("<Id of the button that will open a new window>"));
await elem.click();
let newHandles = await driver.getAllWindowHandles();
while (newHandles.length == initialHandleCount) {
newHandles = await driver.getAllWindowHandles();
}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.
- Use WebDriver to automate Microsoft Edge - An overview of automating Microsoft Edge with the WebDriver protocol.
- Selenium documentation - Information about WebDriver in the context of Selenium, and how to write automated WebDriver tests using Selenium.
- Contact the Microsoft Edge DevTools team to send feedback about using WebDriver, WebDriver testing frameworks (such as Selenium), and Microsoft Edge.
