Invokes a method that is expected to trigger a popup browser window. An that, when run, invokes the popup browser window. The window handle of the popup browser window. Thrown if no popup window appears within the specified timeout. <exception cref=
(Action popupMethod)
| 121 | /// <exception cref="WebDriverTimeoutException">Thrown if no popup window appears within the specified timeout.</exception> |
| 122 | /// <exception cref="ArgumentNullException">Thrown if the action to invoke is <see langword="null"/>.</exception> |
| 123 | public string Invoke(Action popupMethod) |
| 124 | { |
| 125 | if (popupMethod is null) |
| 126 | { |
| 127 | throw new ArgumentNullException(nameof(popupMethod), "popupMethod cannot be null"); |
| 128 | } |
| 129 | |
| 130 | ReadOnlyCollection<string> existingHandles = this.driver.WindowHandles; |
| 131 | popupMethod(); |
| 132 | WebDriverWait wait = new WebDriverWait(SystemClock.Instance, this.driver, this.timeout, this.sleepInterval); |
| 133 | string popupHandle = wait.Until(driver => |
| 134 | { |
| 135 | ReadOnlyCollection<string> newHandles = driver.WindowHandles; |
| 136 | return newHandles.Except(existingHandles, StringComparer.Ordinal).FirstOrDefault(); |
| 137 | }); |
| 138 | |
| 139 | return popupHandle; |
| 140 | } |
| 141 | } |