diff --git a/dotnet/src/support/UI/PopupWindowFinder.cs b/dotnet/src/support/UI/PopupWindowFinder.cs index 4c863e83a01d8..95e57a5ad0385 100644 --- a/dotnet/src/support/UI/PopupWindowFinder.cs +++ b/dotnet/src/support/UI/PopupWindowFinder.cs @@ -18,7 +18,6 @@ // using System; -using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; @@ -132,35 +131,13 @@ public string Invoke(Action popupMethod) ReadOnlyCollection existingHandles = this.driver.WindowHandles; popupMethod(); WebDriverWait wait = new WebDriverWait(SystemClock.Instance, this.driver, this.timeout, this.sleepInterval); - string popupHandle = wait.Until((d) => + string popupHandle = wait.Until(driver => { - string? foundHandle = null; - List differentHandles = GetDifference(existingHandles, this.driver.WindowHandles); - if (differentHandles.Count > 0) - { - foundHandle = differentHandles[0]; - } - - return foundHandle; + ReadOnlyCollection newHandles = driver.WindowHandles; + return newHandles.Except(existingHandles, StringComparer.Ordinal).FirstOrDefault(); }); return popupHandle; } - - private static List GetDifference(ReadOnlyCollection existingHandles, ReadOnlyCollection currentHandles) - { - // We are using LINQ to get the difference between the two lists. - // The non-LINQ version looks like the following: - // List differentHandles = new List(); - // foreach (string handle in currentHandles) - // { - // if (!existingHandles.Contains(handle)) - // { - // currentHandles.Add(handle); - // } - // } - // return differentHandles; - return currentHandles.Except(existingHandles).ToList(); - } } }