File tree Expand file tree Collapse file tree 1 file changed +32
-3
lines changed
dotnet/src/webdriver/Remote Expand file tree Collapse file tree 1 file changed +32
-3
lines changed Original file line number Diff line number Diff line change @@ -126,12 +126,41 @@ public IWebDriver ParentFrame()
126
126
/// <summary>
127
127
/// Change to the Window by passing in the name
128
128
/// </summary>
129
- /// <param name="windowName"> name of the window that you wish to move to</param>
129
+ /// <param name="windowHandleOrName">Window handle or name of the window that you wish to move to</param>
130
130
/// <returns>A WebDriver instance that is currently in use</returns>
131
- public IWebDriver Window ( string windowName )
131
+ public IWebDriver Window ( string windowHandleOrName )
132
132
{
133
133
Dictionary < string , object > parameters = new Dictionary < string , object > ( ) ;
134
- parameters . Add ( "name" , windowName ) ;
134
+ if ( this . driver . IsSpecificationCompliant )
135
+ {
136
+ parameters . Add ( "handle" , windowHandleOrName ) ;
137
+ try
138
+ {
139
+ this . driver . InternalExecute ( DriverCommand . SwitchToWindow , parameters ) ;
140
+ return this . driver ;
141
+ }
142
+ catch ( NoSuchWindowException e )
143
+ {
144
+ // simulate search by name
145
+ string original = this . driver . CurrentWindowHandle ;
146
+ foreach ( string handle in driver . WindowHandles )
147
+ {
148
+ this . Window ( handle ) ;
149
+ if ( windowHandleOrName == this . driver . ExecuteScript ( "return window.name" ) . ToString ( ) )
150
+ {
151
+ return this . driver ; // found by name
152
+ }
153
+ }
154
+
155
+ this . Window ( original ) ;
156
+ throw e ;
157
+ }
158
+ }
159
+ else
160
+ {
161
+ parameters . Add ( "name" , windowHandleOrName ) ;
162
+ }
163
+
135
164
this . driver . InternalExecute ( DriverCommand . SwitchToWindow , parameters ) ;
136
165
return this . driver ;
137
166
}
You can’t perform that action at this time.
0 commit comments