diff --git a/.claude/skills/web-test/scripts/browser.mjs b/.claude/skills/web-test/scripts/browser.mjs index c48e7fda..1056bba6 100644 --- a/.claude/skills/web-test/scripts/browser.mjs +++ b/.claude/skills/web-test/scripts/browser.mjs @@ -143,7 +143,7 @@ import { _detectPlatformDialogs, _closePlatformDialogs, } from './core/errors.mjs'; import { - safeClick, findFieldInputId, + safeClick, findFieldInputId, readEdd, detectNewForm as helperDetectNewForm, } from './core/helpers.mjs'; // Re-export only what was publicly exported before the refactor. @@ -1456,18 +1456,7 @@ async function fillReferenceField(selector, fieldName, value, formNum) { if (dlbVisible) { await page.click(dlbSelector); await page.waitForTimeout(1000); - const eddState = await page.evaluate(`(() => { - const edd = document.getElementById('editDropDown'); - if (!edd || edd.offsetWidth === 0) return { visible: false }; - const eddTexts = [...edd.querySelectorAll('.eddText')].filter(el => el.offsetWidth > 0); - return { - visible: true, - items: eddTexts.map(el => { - const r = el.getBoundingClientRect(); - return { name: el.innerText?.trim() || '', x: r.x + r.width / 2, y: r.y + r.height / 2 }; - }) - }; - })()`); + const eddState = await readEdd(); if (eddState.visible && eddState.items?.length > 0) { const target = normYo(text.toLowerCase()); const candidates = eddState.items.filter(i => !i.name.startsWith('Создать')); @@ -1515,18 +1504,7 @@ async function fillReferenceField(selector, fieldName, value, formNum) { await page.waitForTimeout(2000); // 4. Check editDropDown for autocomplete suggestions - const eddState = await page.evaluate(`(() => { - const edd = document.getElementById('editDropDown'); - if (!edd || edd.offsetWidth === 0) return { visible: false }; - const eddTexts = [...edd.querySelectorAll('.eddText')].filter(el => el.offsetWidth > 0); - return { - visible: true, - items: eddTexts.map(el => { - const r = el.getBoundingClientRect(); - return { name: el.innerText?.trim() || '', x: r.x + r.width / 2, y: r.y + r.height / 2 }; - }) - }; - })()`); + const eddState = await readEdd(); if (eddState.visible && eddState.items?.length > 0) { const target = normYo(text.toLowerCase()); diff --git a/.claude/skills/web-test/scripts/core/helpers.mjs b/.claude/skills/web-test/scripts/core/helpers.mjs index a80cc6c7..4b8615e1 100644 --- a/.claude/skills/web-test/scripts/core/helpers.mjs +++ b/.claude/skills/web-test/scripts/core/helpers.mjs @@ -83,3 +83,25 @@ export async function detectNewForm(prevFormNum, { strict = false } = {}) { return nums.length > 0 ? Math.max(...nums) : null; })()`); } + +/** + * Read the `#editDropDown` autocomplete popup. Returns whether it's visible + * and, when visible, an array of `.eddText` items with display name and + * center coordinates (suitable for page.mouse.click). + * + * @returns {Promise<{visible: boolean, items?: Array<{name:string, x:number, y:number}>}>} + */ +export async function readEdd() { + return await page.evaluate(`(() => { + const edd = document.getElementById('editDropDown'); + if (!edd || edd.offsetWidth === 0) return { visible: false }; + const eddTexts = [...edd.querySelectorAll('.eddText')].filter(el => el.offsetWidth > 0); + return { + visible: true, + items: eddTexts.map(el => { + const r = el.getBoundingClientRect(); + return { name: el.innerText?.trim() || '', x: r.x + r.width / 2, y: r.y + r.height / 2 }; + }) + }; + })()`); +}