diff --git a/lib/helper/Playwright.js b/lib/helper/Playwright.js index b1c8d032e..d06c8edd2 100644 --- a/lib/helper/Playwright.js +++ b/lib/helper/Playwright.js @@ -849,8 +849,8 @@ class Playwright extends Helper { await this.switchTo(null); return frame.reduce((p, frameLocator) => p.then(() => this.switchTo(frameLocator)), Promise.resolve()); } - await this.switchTo(locator); - this.withinLocator = new Locator(locator); + await this.switchTo(frame); + this.withinLocator = new Locator(frame); return; } @@ -2551,14 +2551,17 @@ class Playwright extends Helper { // iframe by selector const els = await this._locate(locator); - // assertElementExists(els, locator); + if (!els[0]) { + throw new Error(`Element ${JSON.stringify(locator)} was not found by text|CSS|XPath`); + } // get content of the first iframe - if ((locator.frame && locator.frame === 'iframe') || locator.toLowerCase() === 'iframe') { + locator = new Locator(locator, 'css'); + if ((locator.frame && locator.frame === 'iframe') || locator.value.toLowerCase() === 'iframe') { contentFrame = await this.page.frames()[1]; // get content of the iframe using its name - } else if (locator.toLowerCase().includes('name=')) { - const frameName = locator.split('=')[1].replace(/"/g, '').replaceAll(/]/g, ''); + } else if (locator.value.toLowerCase().includes('name=')) { + const frameName = locator.value.split('=')[1].replace(/"/g, '').replaceAll(/]/g, ''); contentFrame = await this.page.frame(frameName); } @@ -2566,7 +2569,7 @@ class Playwright extends Helper { this.context = contentFrame; this.contextLocator = null; } else { - this.context = els[0]; + this.context = this.page.frame(this.page.frames()[1].name()); this.contextLocator = locator; } } @@ -3514,7 +3517,10 @@ async function elementSelected(element) { function isFrameLocator(locator) { locator = new Locator(locator); - if (locator.isFrame()) return locator.value; + if (locator.isFrame()) { + const _locator = new Locator(locator.value); + return _locator.value; + } return false; } diff --git a/lib/helper/Puppeteer.js b/lib/helper/Puppeteer.js index 47c6b5629..62f0e2f1c 100644 --- a/lib/helper/Puppeteer.js +++ b/lib/helper/Puppeteer.js @@ -604,8 +604,8 @@ class Puppeteer extends Helper { return this.switchTo(null) .then(() => frame.reduce((p, frameLocator) => p.then(() => this.switchTo(frameLocator)), Promise.resolve())); } - await this.switchTo(locator); - this.withinLocator = new Locator(locator); + await this.switchTo(frame); + this.withinLocator = new Locator(frame); return; } @@ -2602,7 +2602,10 @@ async function elementSelected(element) { function isFrameLocator(locator) { locator = new Locator(locator); - if (locator.isFrame()) return locator.value; + if (locator.isFrame()) { + const _locator = new Locator(locator); + return _locator.value; + } return false; } diff --git a/test/data/app/view/iframe.php b/test/data/app/view/iframe.php index 2004c6035..1c2361558 100755 --- a/test/data/app/view/iframe.php +++ b/test/data/app/view/iframe.php @@ -7,7 +7,7 @@

Iframe test

-