MCPcopy Create free account
hub / github.com/SeleniumHQ/selenium / Window

Method Window

dotnet/src/webdriver/TargetLocator.cs:137–176  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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

Callers 1

NewWindowMethod · 0.95

Calls 5

ThrowIfNullMethod · 0.80
AddMethod · 0.45
ExecuteMethod · 0.45
ToStringMethod · 0.45
ExecuteScriptMethod · 0.45

Tested by

no test coverage detected