mqscript_element_gettext
Extract text content from mobile UI elements using element IDs or selectors for automation testing and data retrieval in mobile applications.
Instructions
Get text from UI element
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| elementId | Yes | Element ID or selector | |
| resultVariable | No | Variable name to store result | elementText |
Implementation Reference
- src/tools/extension-commands.ts:24-35 (handler)The handler function that implements the tool logic. It takes elementId and optional resultVariable, generates an MQScript command to retrieve text from the UI element, and returns a formatted response with the generated script.handler: async (args: { elementId: string; resultVariable?: string }) => { const { elementId, resultVariable = 'elementText' } = args; const script = `${resultVariable} = Element.GetText("${elementId}")`; return { content: [ { type: 'text', text: `Generated MQScript get element text command:\n\`\`\`\n${script}\n\`\`\`\n\nThis gets text from element "${elementId}" and stores it in variable "${resultVariable}".` } ] }; }
- src/tools/extension-commands.ts:9-23 (schema)The input schema defining the parameters for the tool: required elementId (string) and optional resultVariable (string, default 'elementText').inputSchema: { type: 'object' as const, properties: { elementId: { type: 'string', description: 'Element ID or selector' }, resultVariable: { type: 'string', description: 'Variable name to store result', default: 'elementText' } }, required: ['elementId'] },
- src/index.ts:32-61 (registration)The tool is registered by spreading ElementCommands into the ALL_TOOLS object, which is then used in listTools and callTool handlers to provide and execute the tools.const ALL_TOOLS = { // Basic Commands - 基础命令 ...TouchCommands, ...ControlCommands, ...ColorCommands, ...OtherCommands, // Standard Library - 标准库函数 ...MathFunctions, ...StringFunctions, ...TypeConversionFunctions, ...ArrayFunctions, // UI Commands - 界面命令 ...UIControlCommands, ...UIPropertyCommands, ...FloatingWindowCommands, // Extension Commands - 扩展命令 ...ElementCommands, ...DeviceCommands, ...PhoneCommands, ...SysCommands, // Plugin Commands - 插件命令 ...CJsonCommands, ...DateTimeCommands, ...FileCommands, ...TuringCommands, };
- src/index.ts:15-15 (registration)Import of ElementCommands containing the mqscript_element_gettext tool definition.import { ElementCommands, DeviceCommands, PhoneCommands, SysCommands } from './tools/extension-commands.js';