diff --git a/utils/common/device-add.helper.ts b/utils/common/device-add.helper.ts index 1b3f12c..315d5b1 100644 --- a/utils/common/device-add.helper.ts +++ b/utils/common/device-add.helper.ts @@ -177,13 +177,17 @@ export async function selectDeviceCategory(driver: DeviceDriver, categoryName: s if (el) { const rect = await driver.getElementRect(el).catch(() => null); if (rect && rect.width > 0) { - // ★ WDA 会返回**屏外元素**(实测品类常在 y=1192,屏高仅 844)→ 直接点屏外坐标无效="点了没进流程"。 - // 必须先把它**滚进可视区**(y 在 [0.10h, 0.82h])再点:在下方就下滑、在上方就上滑。 - if (rect.y < catH * 0.10 || rect.y + rect.height > catH * 0.82) { + // ★ WDA 会返回**屏外元素**(实测品类常在 y=1192~3941,屏高仅 844)→ 直接点屏外坐标无效="点了没进流程"。 + // 必须先滚进**居中带**(y 在 [0.16h, 0.72h],远离顶部搜索栏/底部栏,避免边缘点空)再点。 + if (rect.y < catH * 0.16 || rect.y + rect.height > catH * 0.72) { if (rect.y > catH * 0.5) await slowScroll(); else await slowScrollUp(); continue; } - await driver.tapElement(el); await sleep(2500); + // 沉降 + 重取 rect(滚动后元素可能仍在动,tapElement 取到移动中的旧坐标 → 点偏)→ 点新鲜中心坐标 + await sleep(450); + const fresh = await driver.getElementRect(el).catch(() => rect); + await driver.tap(Math.round(fresh.x + fresh.width / 2), Math.round(fresh.y + fresh.height / 2)); + await sleep(2500); // ★ 校验真进了流程:**"Add Manually" 是 Add Device 目录页独有标志**,消失=已离开目录进流程 // (不能用 includes(categoryName):目录页本就列着品类名 → 误判成功)。 const after = await driver.getSource();