page_getElement
Get a single page element by CSS selector and return its tag, text, value, size, and offset. Optionally include full outerWXML. Supports subscript selector[N] and innerSelector for shadow DOM.
Instructions
通过选择器获取单个页面元素,相当于 page.$(selector)。返回该元素摘要 {tagName,text,value,size,offset}(取不到的字段为 null,不代表元素不存在);withWxml=true 额外返回完整 outerWxml。支持 selector[index=N] 选第 N 个(0 基,仅作用于 selector,innerSelector 内不支持下标)。⚠️ 单次查询,元素不存在直接抛错——若元素来自 setData 后异步渲染 / SSE 流式 / navigateTo 未稳定,先用 page_waitElement 等到再调本工具;等任意非元素条件(page.data 字段变化等)用 mp_pollUntil。⚠️ page.$ 默认不穿透自定义组件(取决于组件 styleIsolation/addGlobalClass);组件内部元素用 selector(组件)+innerSelector,或 element_getInnerElement(s);本工具的 innerSelector 同样是「在已匹配元素内部再查一层」。结果超过 maxBytes(默认 50000B)返回 {selector,index,truncated,bytes,maxBytes,note,data} 包装——多由 withWxml 引起,可关掉它或调大 maxBytes。
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| maxBytes | No | ||
| selector | Yes | ||
| withWxml | No | ||
| connection | No | 可选连接覆盖(不传则用默认会话)。可用字段:mode(launch|connect)、cliPath、projectPath、wsEndpoint、timeout、port(【自动化端口】→ cli auto --auto-port,默认 9420;不是 IDE HTTP 服务端口,别把 IDE 服务端口传进来)、account、ticket、trustProject、args、cwd、autoClose、autoLaunch、launchTimeout、connectTimeout。 | |
| innerSelector | No |