anandhu
anandhu

Reputation: 780

Selenium Automation fails if Browser Already Open (Edge Chromium/VB.NET/C#)

I am using the below VB.NET code op open Edge Chromium(In IE Capability Mode). It works if there are no existing Edge windows open, Other wise, it just opens another tab in the existing window and just displays This is the initial start page for the WebDriver server. and nothing happens (see screenshot below)

    Dim ieService = InternetExplorerDriverService.CreateDefaultService(Environment.CurrentDirectory, "IEDriverServer.exe")
    Dim ieOptions = New InternetExplorerOptions
    ieOptions.IgnoreZoomLevel = True
    ieOptions.AddAdditionalCapability("ie.edgechromium", True)
    ieOptions.AddAdditionalCapability("ie.edgepath", "C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe")
    Dim driver = New InternetExplorerDriver(ieService, ieOptions, TimeSpan.FromSeconds(60))
    driver.Navigate().GoToUrl("https://example.com")

enter image description here

After one minute, it throws below exception at the line Dim driver = New InternetExplorerDriver(ieService, ieOptions, TimeSpan.FromSeconds(60))

OpenQA.Selenium.WebDriverException: 'The HTTP request to the remote WebDriver server for URL http://localhost:52074/session timed out after 60 seconds.'

Do anyone know how to fix this? (I don't want to kill edge sessions first and then start, because i want the are existing edge windows untouched)

Upvotes: 0

Views: 981

Answers (1)

user27
user27

Reputation: 11

To automate Edge-IE in already opened Edge browser window. Please follow the below steps

  1. Include the application you are trying to launch in Edge-IE browser to the compatibility list of Edge browser(edge://compat)
  2. Include the below command line to start an Edge process before calling Edge-IE driver initialization

code sample

System.Diagnostics.Process.Start(@"msedge.exe", "https://google.com/");
Thread.Sleep(1000);
var dir = "//path of your Edgedriver";
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);}
var ieService = InternetExplorerDriverService.CreateDefaultService(dir, driver);
var ieOptions = new InternetExplorerOptions { };
ieOptions.AddAdditionalCapability("ie.edgechromium", true);
ieOptions.AddAdditionalCapability("ie.edgepath", @"C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe");
InternetExplorerDriver webdriver = new InternetExplorerDriver(ieService, ieOptions, TimeSpan.FromMinutes(3));

Upvotes: 1

Related Questions