element_input
Type text into a specified element in a WeChat Mini Program. Provide a CSS selector and the text value.
Instructions
向指定元素输入文本。
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| connection | No | ||
| selector | Yes | ||
| innerSelector | No | ||
| value | Yes |
Implementation Reference
- src/tools/element.ts:195-220 (handler)Handler function for the element_input tool. Resolves the element by selector (and optional innerSelector), then calls element.input(args.value) to input text. The result is returned as a text message confirming the input.
function createInputTextTool(manager: WeappAutomatorManager): AnyTool { return { name: "element_input", description: "向指定元素输入文本。", parameters: inputTextParameters, execute: async (rawArgs, context: ToolContext) => withUserErrorResult(async () => { const args = inputTextParameters.parse(rawArgs ?? {}); return manager.withPage( context.log, { overrides: args.connection }, async (page) => { const element = await resolveElement( page, args.selector, args.innerSelector ); await element.input(args.value); return toTextResult( `已向元素 "${args.selector}"${args.innerSelector ? ` -> "${args.innerSelector}"` : ""} 输入值 "${args.value}"。` ); } ); }), }; - src/tools/element.ts:25-29 (schema)Input schema for element_input tool: selector (required), innerSelector (optional), value (string or number, coerced).
const inputTextParameters = connectionContainerSchema.extend({ selector: z.string().trim().min(1), innerSelector: z.string().trim().min(1).optional(), value: z.union([z.string(), z.coerce.number()]), }); - src/tools/element.ts:94-100 (registration)Registration of element_input tool within createElementTools(), which is called from src/tools.ts createTools().
export function createElementTools( manager: WeappAutomatorManager ): AnyTool[] { return [ createTapElementTool(manager), createInputTextTool(manager), createCallElementMethodTool(manager),