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) {