2

I want to automate a website in Edge which is require IE mode to be enabled. How can launch Edge in IE mode in selenium?

Below code which I currently use launches Edge in non IE mode, which won't display the website properly.

    Dim edgeDriverService = Microsoft.Edge.SeleniumTools.EdgeDriverService.CreateChromiumService()
    Dim edgeOptions = New Microsoft.Edge.SeleniumTools.EdgeOptions()
    edgeOptions.PageLoadStrategy = PageLoadStrategy.Normal
    edgeOptions.UseChromium = True
    Dim driver As IWebDriver = New Microsoft.Edge.SeleniumTools.EdgeDriver(edgeDriverService, edgeOptions)
    driver.Navigate().GoToUrl("http://example.com")

Tried using edgeOptions.AddAdditionalCapability("ie.edgechromium", True)but it didn't work

anandhu
  • 686
  • 2
  • 13
  • 40

1 Answers1

4

You could refer to the section Automating Internet Explorer mode in this article about how to use IE mode in Edge Chromium in Selenium C#.

You could refer to the following steps:

  1. Download the latest version of IEDriverServer from Selenium site. Here I use 32 bit Windows IE version 3.150.1.
  2. Make some preparations to use IEDriver according to this.
  3. Create a C# console project using Visual Studio.
  4. Install Selenium.WebDriver 3.141.0 nuget package from Nuget package manager.
  5. Add the code below to the project and modify the paths to your owns in the code:
static void Main(string[] args) 
{ 
    var dir = "{FULL_PATH_TO_IEDRIVERSERVER}"; 
    var driver = "IEDriverServer.exe"; 
    if (!Directory.Exists(dir) || !File.Exists(Path.Combine(dir, driver))) 
    { 
        Console.WriteLine("Failed to find {0} in {1} folder.", dir, driver); 
        return; 
    } 

    var ieService = InternetExplorerDriverService.CreateDefaultService(dir, driver); 
    var ieOptions = new InternetExplorerOptions{}; 
    ieOptions.AddAdditionalCapability("ie.edgechromium", true); 
    ieOptions.AddAdditionalCapability("ie.edgepath", "{FULL_PATH_TO_MSEDGE.EXE}"); 

    var webdriver = new InternetExplorerDriver(ieService, ieOptions, TimeSpan.FromSeconds(30)); 
    webdriver.Url = "http://www.example.com"; 
}
  1. Run the project to test:

enter image description here

Notes:

  1. Make sure to close all the Edge browser tabs and window before running the code.
  2. Use full paths in the code. For example: ieOptions.AddAdditionalCapability("ie.edgepath", @"C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe");.
Yu Zhou
  • 11,532
  • 1
  • 8
  • 22
  • 1
    Hi, Thanks for this it worked. Marking it as solution since it answers my question. However i faced another issue, I had to make Edge Headless aswell. How will i do that now?? Earlier i gave it as edgeOptions.AddArguments("--headless"). Since now i use ieoptions,, i cant make headless? :-( – anandhu Aug 24 '20 at 12:43
  • I noticed that this code is failing if i already have an edge windows open. is there some way to fix this? if already edge window is open, it opens another tab and displays "This is the initial start page for the WebDriver server" and then nothing happens – anandhu Aug 25 '20 at 16:09
  • 2
    Yes, so I point out in the Notes that you need to close all the Edge browser tabs and window before running the code. We can only avoid this by doing so. – Yu Zhou Aug 26 '20 at 02:49