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 '