From 184e4773a4db2e1983378048becc3a9b603a4e55 Mon Sep 17 00:00:00 2001 From: Nick Shirokov Date: Thu, 12 Mar 2026 17:43:06 +0300 Subject: [PATCH] fix(web-test): clickElement retries when modal form is still loading After F4/Enter that opens a modal, clickElement could fail because detectFormScript found the parent form before the modal appeared. Now retries up to 2s, re-detecting the form each time. Co-Authored-By: Claude Opus 4.6 --- .claude/skills/web-test/scripts/browser.mjs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/.claude/skills/web-test/scripts/browser.mjs b/.claude/skills/web-test/scripts/browser.mjs index 0df07237..5483f75e 100644 --- a/.claude/skills/web-test/scripts/browser.mjs +++ b/.claude/skills/web-test/scripts/browser.mjs @@ -1363,11 +1363,25 @@ export async function clickElement(text, { dblclick } = {}) { // No match in popup — fall through to form elements } - const formNum = await page.evaluate(detectFormScript()); + let formNum = await page.evaluate(detectFormScript()); if (formNum === null) throw new Error(`clickElement: no form found`); // Find the target element ID - const target = await page.evaluate(findClickTargetScript(formNum, text)); + let target = await page.evaluate(findClickTargetScript(formNum, text)); + + // Retry: if not found, a modal form may still be loading (e.g. after F4). + // Wait up to 2s for a new form to appear and re-detect. + if (target?.error) { + for (let retry = 0; retry < 4; retry++) { + await page.waitForTimeout(500); + const newForm = await page.evaluate(detectFormScript()); + if (newForm !== null && newForm !== formNum) { + formNum = newForm; + target = await page.evaluate(findClickTargetScript(formNum, text)); + if (!target?.error) break; + } + } + } if (target?.error) throw new Error(`clickElement: "${text}" not found. Available: ${target.available?.join(', ') || 'none'}`); // Grid row targets — use coordinate click (single or double)