From cf1e5608025165e003f190fa2a3fc4012af6202d Mon Sep 17 00:00:00 2001 From: yu <1919727607@qq.com> Date: Thu, 5 Nov 2026 11:15:36 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=83=E7=B4=A0=E6=8B=BE=E5=8F=96=E6=B3=9B?= =?UTF-8?q?=E5=8C=96=E5=8A=A8=E6=80=81=E8=AE=B0=E5=BD=95id:=20=E9=95=BF?= =?UTF-8?q?=E6=95=B0=E5=AD=97=E7=BB=93=E5=B0=BE=E5=94=AF=E4=B8=80id?= =?UTF-8?q?=E8=87=AA=E5=8A=A8=E8=BD=AC=E4=B8=BA=E5=89=8D=E7=BC=80=E5=8C=B9?= =?UTF-8?q?=E9=85=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 淘宝等站点卡片根节点 id 为动态记录 id(如 item_id_1087512368188), 原样生成导致选择器只命中一张卡 - stable() 检测 id 以长数字(6位以上)结尾时, 若 [id^=前缀] 命中多个元素则优先采用, 使选择器覆盖所有同类卡片 - 拾取器与元素引用两处 cssPath 同步修改 --- src/main/browser/session.ts | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/main/browser/session.ts b/src/main/browser/session.ts index 962fe1d..3c93e03 100644 --- a/src/main/browser/session.ts +++ b/src/main/browser/session.ts @@ -297,8 +297,18 @@ export class BrowserSession implements BrowserLike { const localPath = (start, root) => { const stable = (item) => { if (item.id) { + // 长数字结尾的唯一 id 多为动态记录 id(如淘宝 item_id_1087512368188),泛化为前缀匹配以命中所有同类卡片 + const dynamic = /^(.*?[-_])\d{6,}$/.exec(item.id); + if (dynamic) { + const generalized = '[id^="' + cssEscape(dynamic[1]) + '"]'; + try { if (root.querySelectorAll(generalized).length > 1) return generalized; } catch {} + } const candidate = '#' + cssEscape(item.id); try { if (root.querySelectorAll(candidate).length === 1) return candidate; } catch {} + if (dynamic) { + const generalized = '[id^="' + cssEscape(dynamic[1]) + '"]'; + try { if (root.querySelectorAll(generalized).length >= 1) return generalized; } catch {} + } } const testId = item.getAttribute('data-testid'); if (testId) { @@ -1276,8 +1286,18 @@ const PICKER_BOOTSTRAP_SOURCE = `(() => { const localPath = (start, root) => { const stable = (item) => { if (item.id) { + // 长数字结尾的唯一 id 多为动态记录 id(如淘宝 item_id_1087512368188),泛化为前缀匹配以命中所有同类卡片 + const dynamic = /^(.*?[-_])\d{6,}$/.exec(item.id); + if (dynamic) { + const generalized = '[id^="' + cssEscape(dynamic[1]) + '"]'; + try { if (root.querySelectorAll(generalized).length > 1) return generalized; } catch {} + } const candidate = '#' + cssEscape(item.id); try { if (root.querySelectorAll(candidate).length === 1) return candidate; } catch {} + if (dynamic) { + const generalized = '[id^="' + cssEscape(dynamic[1]) + '"]'; + try { if (root.querySelectorAll(generalized).length >= 1) return generalized; } catch {} + } } const testId = item.getAttribute('data-testid'); if (testId) {