Skip to main content
Glama

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

TableJSON Schema
NameRequiredDescriptionDefault
maxBytesNo
selectorYes
withWxmlNo
connectionNo可选连接覆盖(不传则用默认会话)。可用字段: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。
innerSelectorNo
Behavior5/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

The description discloses behavioral traits: imputed null fields do not indicate absence, element not found throws error, selector supports index[N] but innerSelector does not, default maxBytes and truncation behavior. No annotations are present, so the description carries the full burden and meets it well.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is long but well-structured with warnings and examples. It front-loads the core purpose and uses clear formatting. Minor reduction in length could be possible, but every sentence adds value.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the complexity (5 parameters, nested objects, no output schema), the description covers return format, error handling, async considerations, component isolation, and truncation. It provides sufficient context for correct invocation.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters5/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is only 20%, but the description adds significant meaning for all parameters: selector syntax (index[N]), innerSelector purpose, withWxml effect, maxBytes behavior, and connection object details (including port warnings). This compensates fully for the low schema coverage.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool gets a single page element by selector, equivalent to page.$(selector). It details the return summary fields and distinguishes from sibling tools like page_getElements (plural) and element_getInnerElement (for inner elements from an element handle).

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides explicit guidance on when to use the tool vs alternatives: it warns that elements from async rendering require page_waitElement first, and for non-element conditions use mp_pollUntil. It also explains innerSelector usage for custom components and mentions maxBytes truncation behavior.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/Chaixueyuan/weapp-agent-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server