anandhu
anandhu

Reputation: 780

How to enable IE mode in Chromium Edge Browser in selenium C#?

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

Upvotes: 2

Views: 8619

Answers (1)

Yu Zhou
Yu Zhou

Reputation: 12999

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");.

Upvotes: 4

Related Questions