File tree Expand file tree Collapse file tree
javascript/node/selenium-webdriver Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -2167,16 +2167,18 @@ class TargetLocator {
21672167 * when the driver has changed focus to the specified frame.
21682168 */
21692169 frame ( id ) {
2170- let frameReference = id ;
2171-
2172- if ( typeof id === "string" ) {
2173- frameReference = this . driver_ . findElement ( {
2174- id : id
2175- } ) ;
2170+ let frameReference = id
2171+ if ( typeof id === 'string' ) {
2172+ frameReference = this . driver_
2173+ . findElement ( { id } )
2174+ . catch ( ( _ ) => this . driver_ . findElement ( { name : id } ) )
21762175 }
21772176
21782177 return this . driver_ . execute (
2179- new command . Command ( command . Name . SWITCH_TO_FRAME ) . setParameter ( 'id' , frameReference )
2178+ new command . Command ( command . Name . SWITCH_TO_FRAME ) . setParameter (
2179+ 'id' ,
2180+ frameReference
2181+ )
21802182 )
21812183 }
21822184
Original file line number Diff line number Diff line change @@ -64,4 +64,18 @@ test.suite(function (env) {
6464 'This page has iframes'
6565 )
6666 } )
67+
68+ it ( 'can switch to a frame by name' , async function ( ) {
69+ await driver . get ( test . Pages . iframePage )
70+ await driver . switchTo ( ) . frame ( 'iframe1-name' )
71+ assert . strictEqual (
72+ await driver . executeScript ( 'return document.title' ) ,
73+ 'We Leave From Here'
74+ )
75+ await driver . switchTo ( ) . parentFrame ( )
76+ assert . strictEqual (
77+ await driver . executeScript ( 'return document.title' ) ,
78+ 'This page has iframes'
79+ )
80+ } )
6781} )
You can’t perform that action at this time.
0 commit comments