I updated Selenium to 4. I test legacy app that runs only on IE. Now IE will be closed down and I need to switch to MS Egde in capability mode. My tests during execution need to switch to new browser windows and uses function IWebDriver.WindowHandles to do it (code below).

I had to add new options for a driver to run test on Edge like this:

var options = new InternetExplorerOptions();
options.AttachToEdgeChrome = true; 
options.EdgeExecutablePath = @"\msedge.exe";

Then I use code like this to switch between browser windows:

public Context SwitchToNewIEWindow(string windowTitle, bool isEqual = true)
        {
            for (int i = 0; i < context.GetTimeout().Seconds; i++)
            {
                try
                {
                    var ieWindowHandlers = context.GetDriver().WindowHandles;
                    foreach(var handler in ieWindowHandlers)
                    {
                        var window = context.GetDriver().SwitchTo().Window(handler);
                        bool condition = isEqual ? window.Title == windowTitle : window.Title.Contains(windowTitle);
                        if (condition)
                        {
                            context.SetDriver(window);
                            context.SetCurrentWindow(windowTitle);
                            return context;
                        }
                    }
                }
                catch (Exception)
                {
                    context.Wait(1);
                }
            }
            throw new Exception($"No window found with title: {windowTitle}");

        }

In Selenium 3 everything works fine and WindowHandles function returns 2 handles. In Selenium 4 and IEDriver in Edge mode this function returns 1 handle.I have read https://github.com/SeleniumHQ/selenium/issues/8868 but in my case waiting a few seconds does not change anything. Even after a minute I still get only handle of first window. Any suggestions how to make it work properly again in Selenium 4.

Libraries and its versions:enter image description here

0

There are 0 best solutions below