From a0916ebda20352ff7f6ed1a436e9eefc64944ab4 Mon Sep 17 00:00:00 2001 From: butubb <1422726308@qq.com> Date: Wed, 19 Aug 2026 15:10:26 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=8A=93=E5=8F=96=E5=85=83=E7=B4=A0?= =?UTF-8?q?=E5=9B=9E=E5=A1=AB=E5=9E=83=E5=9C=BE=E9=80=89=E6=8B=A9=E5=99=A8?= =?UTF-8?q?=E2=80=94=E2=80=94=E6=97=A0=E5=B1=9E=E6=80=A7=E5=85=83=E7=B4=A0?= =?UTF-8?q?=E7=94=9F=E6=88=90=20//*[N]=EF=BC=88=E5=8C=B9=E9=85=8D=E4=BB=BB?= =?UTF-8?q?=E6=84=8F=E8=8A=82=E7=82=B9=E7=82=B9=E4=B8=8D=E5=88=B0=EF=BC=89?= =?UTF-8?q?=EF=BC=8C=E6=94=B9=E4=B8=BA=20invalid=20=E6=A0=87=E8=AE=B0?= =?UTF-8?q?=E5=89=8D=E7=AB=AF=E6=8F=90=E7=A4=BA=E4=B8=8D=E5=8F=AF=E9=80=89?= =?UTF-8?q?=EF=BC=9B=E7=BB=93=E6=9E=84=E8=B7=AF=E5=BE=84=E8=B7=B3=E8=BF=87?= =?UTF-8?q?=E6=97=A0=20class=20=E5=B1=82=E6=B6=88=E9=99=A4=20//*[N]=20?= =?UTF-8?q?=E5=89=8D=E7=BC=80=E6=B1=A1=E6=9F=93=EF=BC=9B=E6=A8=A1=E5=9D=97?= =?UTF-8?q?=E6=8B=86=E5=88=86=E9=81=97=E6=BC=8F=E4=BF=AE=E5=A4=8D=EF=BC=88?= =?UTF-8?q?get=5Fall=5Fworker=5Fstatus/list=5Finstalled=5Fapps=20=E8=87=B4?= =?UTF-8?q?=20summary/=E8=AE=BE=E5=A4=87=E5=B7=B2=E8=A3=85=E5=BA=94?= =?UTF-8?q?=E7=94=A8=20500=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/uiauto_helper.py | 22 +++++++++++++++++----- static/admin/editor.js | 5 +++++ web/monitor.py | 5 +++-- 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/core/uiauto_helper.py b/core/uiauto_helper.py index 76c58e6..69fe8ba 100644 --- a/core/uiauto_helper.py +++ b/core/uiauto_helper.py @@ -190,9 +190,14 @@ def _extract(root, out): desc = props.get("content-desc", "") cls = props.get("class", "") tag = cls.split(".")[-1] if cls else "*" - # 始终带同 class 兄弟序号(含 [1]),结构路径才精确无歧义 - seg = f"{tag}[{tag_index}]" - own_tag_path = f"{tag_path}/{seg}" if tag_path else seg + # 始终带同 class 兄弟序号(含 [1]),结构路径才精确无歧义; + # class 为空的层(tag=*)不参与结构路径,避免 //*[N] 前缀污染导致选择器定位到任意节点 + if tag != "*": + seg = f"{tag}[{tag_index}]" + own_tag_path = f"{tag_path}/{seg}" if tag_path else seg + else: + seg = "" + own_tag_path = tag_path # ---- 推荐选择器:唯一属性 > 锚点祖先限定 > 全结构路径 ---- if rid: @@ -206,8 +211,15 @@ def _extract(root, out): suggested = {"type": "xpath", "value": val} child_ctx = val else: - # 无唯一属性且无锚点祖先:用从根开始的结构路径(脆弱,标记 broad 让前端提示) - suggested = {"type": "xpath", "value": f"//{own_tag_path}", "broad": True} + if tag == "*": + # class 也为空的元素:结构路径 //*[N] 无意义(匹配到文档任意节点), + # 标记 invalid,前端提示不可选,避免回填垃圾选择器导致"点击不到" + suggested = {"type": "xpath", "value": "", + "invalid": True, + "reason": "该元素无可用属性(id/文本/class),无法生成可靠选择器"} + else: + # 无唯一属性且无锚点祖先:用从根开始的结构路径(脆弱,标记 broad 让前端提示) + suggested = {"type": "xpath", "value": f"//{own_tag_path}", "broad": True} child_ctx = None out.append({ diff --git a/static/admin/editor.js b/static/admin/editor.js index 2561fc0..f58b12a 100644 --- a/static/admin/editor.js +++ b/static/admin/editor.js @@ -998,6 +998,7 @@ var _stepEditor={ if(el.description)attrs.push('desc:'+esc(el.description)+''); var indent=' '.repeat(Math.min(el.depth||0,6)); var sg=el.suggested||{}; + if(sg.invalid)attrs.push('⚠ '+esc(sg.reason||'无可用属性')+''); return '