From f259711c4ed4158281906cb04deca4ca8c4ad3b8 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 31 Oct 2026 06:19:47 +0000 Subject: [PATCH 1/2] Initial plan From 7303590e9ec9da5c1005a2b331d324397925643b Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 31 Oct 2026 06:22:18 +0000 Subject: [PATCH 2/2] Apply remaining changes Co-authored-by: kobenguyent <7845001+kobenguyent@users.noreply.github.com> --- lib/helper/Playwright.js | 17 ++++++++++------- test/helper/webapi.js | 5 +++++ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/lib/helper/Playwright.js b/lib/helper/Playwright.js index 6cfcf420a..1bc4c7737 100644 --- a/lib/helper/Playwright.js +++ b/lib/helper/Playwright.js @@ -3576,13 +3576,16 @@ class Playwright extends Helper { const locator = new Locator(context, 'css') try { if (!locator.isXPath()) { - return contextObject - .locator(`${locator.simplify()} >> text=${text}`) - .first() - .waitFor({ timeout: waitTimeout, state: 'visible' }) - .catch(e => { - throw new Error(errorMessage) - }) + const deadline = Date.now() + waitTimeout + do { + const els = await this._locate(locator) + for (const el of els) { + const texts = await el.evaluateAll(nodes => nodes.map(node => node.innerText ?? node.textContent)) + if (texts.some(t => typeof t === 'string' && t.includes(text))) return + } + await new Promise(resolve => setTimeout(resolve, 100)) + } while (Date.now() < deadline) + throw new Error(errorMessage) } if (locator.isXPath()) { diff --git a/test/helper/webapi.js b/test/helper/webapi.js index 9f1b08ad9..ad3acb105 100644 --- a/test/helper/webapi.js +++ b/test/helper/webapi.js @@ -1678,6 +1678,11 @@ export function tests() { await I.see('Dynamic text') }) + it('should wait for text in context with locator.at', async () => { + await I.amOnPage('/dynamic') + await I.waitForText('Dynamic text', 2, new Locator('#text').at(1)) + }) + it('should fail if no context', async function () { let failed = false await I.amOnPage('/dynamic')