| 
18 | 18 | // </copyright>  | 
19 | 19 | 
 
  | 
20 | 20 | using System;  | 
21 |  | -using System.Collections.Generic;  | 
22 | 21 | using System.Collections.ObjectModel;  | 
23 | 22 | using System.Linq;  | 
24 | 23 | 
 
  | 
@@ -132,35 +131,13 @@ public string Invoke(Action popupMethod)  | 
132 | 131 |             ReadOnlyCollection<string> existingHandles = this.driver.WindowHandles;  | 
133 | 132 |             popupMethod();  | 
134 | 133 |             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 =>  | 
136 | 135 |             {  | 
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();  | 
145 | 138 |             });  | 
146 | 139 | 
 
  | 
147 | 140 |             return popupHandle;  | 
148 | 141 |         }  | 
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 |  | -        }  | 
165 | 142 |     }  | 
166 | 143 | }  | 
0 commit comments