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

Method Window

dotnet/src/webdriver/TargetLocator.cs:136–175  ·  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

134 /// <returns>A WebDriver instance that is currently in use</returns>
135 /// <exception cref="ArgumentNullException">If <paramref name="windowHandleOrName"/> is <see langword="null"/>.</exception>
136 public IWebDriver Window(string windowHandleOrName)
137 {
138 ArgumentNullException.ThrowIfNull(windowHandleOrName);
139
140 Dictionary<string, object?> parameters = new Dictionary<string, object?>();
141 parameters.Add("handle", windowHandleOrName);
142 try
143 {
144 this.driver.Execute(DriverCommand.SwitchToWindow, parameters);
145 return this.driver;
146 }
147 catch (NoSuchWindowException)
148 {
149 // simulate search by name
150 string? original = null;
151 try
152 {
153 original = this.driver.CurrentWindowHandle;
154 }
155 catch (NoSuchWindowException)
156 {
157 }
158
159 foreach (string handle in this.driver.WindowHandles)
160 {
161 this.Window(handle);
162 if (windowHandleOrName == this.driver.ExecuteScript("return window.name")!.ToString())
163 {
164 return this.driver; // found by name
165 }
166 }
167
168 if (original != null)
169 {
170 this.Window(original);
171 }
172
173 throw;
174 }
175 }
176
177 /// <summary>
178 /// 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