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 <noreply@anthropic.com>
This commit is contained in:
Nick Shirokov
2026-03-12 17:43:06 +03:00
parent 23f4cc0bbd
commit 184e4773a4
+16 -2
View File
@@ -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)