Change to the Window by passing in the name Window handle or name of the window that you wish to move to A WebDriver instance that is currently in use If is .
(string windowHandleOrName)
| 135 | /// <returns>A WebDriver instance that is currently in use</returns> |
| 136 | /// <exception cref="ArgumentNullException">If <paramref name="windowHandleOrName"/> is <see langword="null"/>.</exception> |
| 137 | public IWebDriver Window(string windowHandleOrName) |
| 138 | { |
| 139 | ArgumentNullException.ThrowIfNull(windowHandleOrName); |
| 140 | |
| 141 | Dictionary<string, object?> parameters = new Dictionary<string, object?>(); |
| 142 | parameters.Add("handle", windowHandleOrName); |
| 143 | try |
| 144 | { |
| 145 | this.driver.Execute(DriverCommand.SwitchToWindow, parameters); |
| 146 | return this.driver; |
| 147 | } |
| 148 | catch (NoSuchWindowException) |
| 149 | { |
| 150 | // simulate search by name |
| 151 | string? original = null; |
| 152 | try |
| 153 | { |
| 154 | original = this.driver.CurrentWindowHandle; |
| 155 | } |
| 156 | catch (NoSuchWindowException) |
| 157 | { |
| 158 | } |
| 159 | |
| 160 | foreach (string handle in this.driver.WindowHandles) |
| 161 | { |
| 162 | this.Window(handle); |
| 163 | if (windowHandleOrName == this.driver.ExecuteScript("return window.name")!.ToString()) |
| 164 | { |
| 165 | return this.driver; // found by name |
| 166 | } |
| 167 | } |
| 168 | |
| 169 | if (original != null) |
| 170 | { |
| 171 | this.Window(original); |
| 172 | } |
| 173 | |
| 174 | throw; |
| 175 | } |
| 176 | } |
| 177 | |
| 178 | /// <summary> |
| 179 | /// Creates a new browser window and switches the focus for future commands |
no test coverage detected