Skip to content

Commit b9d91b4

Browse files
[dotnet] Simplify PopupWindowFinder.Invoke (#15549)
1 parent 2f25394 commit b9d91b4

File tree

1 file changed

+3
-26
lines changed

1 file changed

+3
-26
lines changed

dotnet/src/support/UI/PopupWindowFinder.cs

+3-26
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
// </copyright>
1919

2020
using System;
21-
using System.Collections.Generic;
2221
using System.Collections.ObjectModel;
2322
using System.Linq;
2423

@@ -132,35 +131,13 @@ public string Invoke(Action popupMethod)
132131
ReadOnlyCollection<string> existingHandles = this.driver.WindowHandles;
133132
popupMethod();
134133
WebDriverWait wait = new WebDriverWait(SystemClock.Instance, this.driver, this.timeout, this.sleepInterval);
135-
string popupHandle = wait.Until<string>((d) =>
134+
string popupHandle = wait.Until(driver =>
136135
{
137-
string? foundHandle = null;
138-
List<string> differentHandles = GetDifference(existingHandles, this.driver.WindowHandles);
139-
if (differentHandles.Count > 0)
140-
{
141-
foundHandle = differentHandles[0];
142-
}
143-
144-
return foundHandle;
136+
ReadOnlyCollection<string> newHandles = driver.WindowHandles;
137+
return newHandles.Except(existingHandles, StringComparer.Ordinal).FirstOrDefault();
145138
});
146139

147140
return popupHandle;
148141
}
149-
150-
private static List<string> GetDifference(ReadOnlyCollection<string> existingHandles, ReadOnlyCollection<string> currentHandles)
151-
{
152-
// We are using LINQ to get the difference between the two lists.
153-
// The non-LINQ version looks like the following:
154-
// List<string> differentHandles = new List<string>();
155-
// foreach (string handle in currentHandles)
156-
// {
157-
// if (!existingHandles.Contains(handle))
158-
// {
159-
// currentHandles.Add(handle);
160-
// }
161-
// }
162-
// return differentHandles;
163-
return currentHandles.Except(existingHandles).ToList();
164-
}
165142
}
166143
}

0 commit comments

Comments
 (0)