@@ -850,8 +850,8 @@ class Playwright extends Helper {
850850 await this . switchTo ( null ) ;
851851 return frame . reduce ( ( p , frameLocator ) => p . then ( ( ) => this . switchTo ( frameLocator ) ) , Promise . resolve ( ) ) ;
852852 }
853- await this . switchTo ( locator ) ;
854- this . withinLocator = new Locator ( locator ) ;
853+ await this . switchTo ( frame ) ;
854+ this . withinLocator = new Locator ( frame ) ;
855855 return ;
856856 }
857857
@@ -2552,22 +2552,25 @@ class Playwright extends Helper {
25522552
25532553 // iframe by selector
25542554 const els = await this . _locate ( locator ) ;
2555- // assertElementExists(els, locator);
2555+ if ( ! els [ 0 ] ) {
2556+ throw new Error ( `Element ${ JSON . stringify ( locator ) } was not found by text|CSS|XPath` ) ;
2557+ }
25562558
25572559 // get content of the first iframe
2558- if ( ( locator . frame && locator . frame === 'iframe' ) || locator . toLowerCase ( ) === 'iframe' ) {
2560+ locator = new Locator ( locator , 'css' ) ;
2561+ if ( ( locator . frame && locator . frame === 'iframe' ) || locator . value . toLowerCase ( ) === 'iframe' ) {
25592562 contentFrame = await this . page . frames ( ) [ 1 ] ;
25602563 // get content of the iframe using its name
2561- } else if ( locator . toLowerCase ( ) . includes ( 'name=' ) ) {
2562- const frameName = locator . split ( '=' ) [ 1 ] . replace ( / " / g, '' ) . replaceAll ( / ] / g, '' ) ;
2564+ } else if ( locator . value . toLowerCase ( ) . includes ( 'name=' ) ) {
2565+ const frameName = locator . value . split ( '=' ) [ 1 ] . replace ( / " / g, '' ) . replaceAll ( / ] / g, '' ) ;
25632566 contentFrame = await this . page . frame ( frameName ) ;
25642567 }
25652568
25662569 if ( contentFrame ) {
25672570 this . context = contentFrame ;
25682571 this . contextLocator = null ;
25692572 } else {
2570- this . context = els [ 0 ] ;
2573+ this . context = this . page . frame ( this . page . frames ( ) [ 1 ] . name ( ) ) ;
25712574 this . contextLocator = locator ;
25722575 }
25732576 }
@@ -3515,7 +3518,10 @@ async function elementSelected(element) {
35153518
35163519function isFrameLocator ( locator ) {
35173520 locator = new Locator ( locator ) ;
3518- if ( locator . isFrame ( ) ) return locator . value ;
3521+ if ( locator . isFrame ( ) ) {
3522+ const _locator = new Locator ( locator . value ) ;
3523+ return _locator . value ;
3524+ }
35193525 return false ;
35203526}
35213527
0 commit comments