DEV Community

jsakamoto
jsakamoto

Posted on

Use Selenium to automate IE mode in Microsoft Edge on Windows 11

Introduction

Today, the latest stable version of Windows OS (It is Windows 11 as of the writing of this article) no longer supports Internet Explorer as a standalone application.

However, Internet Explorer hasn't died yet.

Internet Explorer is still alive inside Microsoft Edge browser as "IE mode".

So there is still worth automating IE mode in Microsoft Edge for E2E testing by "Selenium" with Internet Explorer Driver.

There is even official Microsoft documentation for automating IE mode in Microsoft Edge.

https://docs.microsoft.com/en-us/microsoft-edge/webdriver-chromium/ie-mode

In some cases, the official document is not enough...

However, in some cases, you may run into runtime errors at automating IE mode in Microsoft Edge browser by Selenium even you certainly follow the steps in the official document.

In my case, I was using Selenium .NET binding with C# on Windows 11, I had to do additional two steps as the following list to make it works fine:

  • Set the IgnoreZoomLevel property of the InternetExplorerOptions object to true.
  • Set the Turn on Protected Mode local group policy to Enable for all zones.

I will explain more details of the above in the following sections of this article.

Ignore the zoom level

At first, the C# code I wrote was like below:

var driver = new InternetExplorerDriver(new InternetExplorerOptions {
  AttachToEdgeChrome = true,
  EdgeExecutablePath = "C:/Program Files (x86)/Microsoft/Edge/Application/msedge.exe"
});
...
Enter fullscreen mode Exit fullscreen mode

The C# code above is equivalent to the official document's code.

But unfortunately, I ran into an error.

As I mentioned above, I was using Selenium .NET binding, so I saw the unhandled exception message on my application's console as below.

Started InternetExplorerDriver server (32-bit)
4.0.0.0
Listening on port 54479
Only local connections are allowed

Unhandled exception. 
System.InvalidOperationException: 
Unexpected error launching Internet Explorer. 
Browser zoom level was set to 175%. It should be set to 100% (SessionNotCreated)
Enter fullscreen mode Exit fullscreen mode

The exception message said, "the zoom level of the browser must be 100%, but it was not".

However, I've never changed the zoom level, and the Edge browser zoom level indicated 100% in its menu at that time.

Therefore, finally, I decided to make Selenium ignore the zoom level forcibly.

We can do that by the IgnoreZoomLevel property of the InternetExplorerOptions object to true.

var driver = new InternetExplorerDriver(new InternetExplorerOptions {
  AttachToEdgeChrome = true,
  EdgeExecutablePath = "C:/Program Files (x86)/Microsoft/Edge/Application/msedge.exe",
  IgnoreZoomLevel = true // ๐Ÿ‘ˆ Added this line.
});
...
Enter fullscreen mode Exit fullscreen mode

Turn on "Protected Mode" of IE... on Windows 11!

Unfortunately, even I avoided 1st error above, and I ran into 2nd error.

The console displayed the error message like below:

Started InternetExplorerDriver server (32-bit)
4.0.0.0
Listening on port 56568
Only local connections are allowed

Unhandled exception. 
OpenQA.Selenium.WebDriverException: 
The HTTP request to the remote WebDriver server for URL http://localhost:56568/session/c81cd23a-2f60-45ae-9636-ebd27fea9c22/url timed out after 60 seconds.
 ---> System.Threading.Tasks.TaskCanceledException: 
 The request was canceled due to the configured HttpClient.Timeout of 60 seconds elapsing.
 ---> System.TimeoutException: The operation was canceled.
Enter fullscreen mode Exit fullscreen mode

The error message said the operation of the browser was timed out.
And when I saw that error message, I was immediately reminded that the error might be related to IE's "Protected Mode" configuration.

That means we have to set IE's "Protected Mode" configuration to "Enable" for all zones before automating IE.

That requirement is also mentioned in the official documents of Selenium.

https://www.selenium.dev/documentation/ie_driver_server/#required-configuration

you must set the Protected Mode settings for each zone to be the same value.

Therefore I opened the "Internet Properties" dialog from the Control Panel in a hurry for enabling IE's "Protected Mode".
But the "Enable Protected Mode" check box did not exist in the dialog... because it is Windows 11!

the "Internet Properties" dialog

I stood there in confusion for a while, but I pulled myself together and started searching on the Internet to resolve this problem.

Before long, fortunately, I found the answer in the article written in 2016 below.

https://www.urtech.ca/2016/01/solved-how-to-disable-protected-mode-in-internet-explorer-using-gpo/

Actually, we could control the IE's "Protected Mode" by Local Group Policy.

So I opened Group Policy Editor (gpedit.msc), set the "Protected Mode" policy of all zones to "Enable", and applied it immediately by performing the gpupdate /force command.

Group Policy Editor

After I did all of them, my C# code that is automating IE mode in Microsoft Edge had been started to work fine. ๐ŸŽ‰

Conclusion

I hope this article will save time for developers who have to automate IE mode in Microsoft Edge by Selenium and IE Driver.

Learn, Practice, Share. :)

Top comments (0)