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 @@ -2162,13 +2162,21 @@ class TargetLocator {
21622162 * If the specified frame can not be found, the returned promise will be
21632163 * rejected with a {@linkplain error.NoSuchFrameError}.
21642164 *
2165- * @param {(number|WebElement|null) } id The frame locator.
2165+ * @param {(number|string| WebElement|null) } id The frame locator.
21662166 * @return {!Promise<void> } A promise that will be resolved
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+ } ) ;
2176+ }
2177+
21702178 return this . driver_ . execute (
2171- new command . Command ( command . Name . SWITCH_TO_FRAME ) . setParameter ( 'id' , id )
2179+ new command . Command ( command . Name . SWITCH_TO_FRAME ) . setParameter ( 'id' , frameReference )
21722180 )
21732181 }
21742182
Original file line number Diff line number Diff line change @@ -50,4 +50,18 @@ test.suite(function (env) {
5050 'This page has iframes'
5151 )
5252 } )
53+
54+ it ( 'can switch to a frame by id' , async function ( ) {
55+ await driver . get ( test . Pages . iframePage )
56+ await driver . switchTo ( ) . frame ( "iframe1" )
57+ assert . strictEqual (
58+ await driver . executeScript ( 'return document.title' ) ,
59+ 'We Leave From Here'
60+ )
61+ await driver . switchTo ( ) . parentFrame ( )
62+ assert . strictEqual (
63+ await driver . executeScript ( 'return document.title' ) ,
64+ 'This page has iframes'
65+ )
66+ } )
5367} )
You can’t perform that action at this time.
0 commit comments