Skip to main content
Glama

clearText

Remove text from the currently focused input field on mobile devices to automate testing and streamline data entry tasks.

Instructions

Clear text from the currently focused input field

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
platformYesPlatform of the device

Implementation Reference

  • Registers the clearText tool in the ToolRegistry with name, description, schema, and handler function.
    ToolRegistry.registerDeviceAware( "clearText", "Clear text from the currently focused input field", clearTextSchema, clearTextHandler, true // Supports progress notifications );
  • The registered handler for the clearText tool, which instantiates ClearText class and executes it.
    const clearTextHandler = async (device: BootedDevice, args: ClearTextArgs, progress?: ProgressCallback) => { try { const clearText = new ClearText(device); const result = await clearText.execute(progress); return createJSONToolResponse({ message: "Cleared text from input field", observation: result.observation, ...result }); } catch (error) { throw new ActionableError(`Failed to clear text: ${error}`); } };
  • Zod schema defining the input arguments for the clearText tool.
    export const clearTextSchema = z.object({ platform: z.enum(["android", "ios"]).describe("Platform of the device") });
  • Core execution logic of ClearText class, finds focused text field length and clears it by sending delete keyevents.
    async execute(progress?: ProgressCallback): Promise<ClearTextResult> { return this.observedInteraction( async (observeResult: ObserveResult) => { try { if (!observeResult.viewHierarchy) { // Fallback: if we can't get view hierarchy, use a reasonable default await this.clearWithDeletes(200); return { success: true }; } let textLength = 0; // Look for focused elements first by traversing and checking attributes textLength = this.findFocusedElementTextLength(observeResult.viewHierarchy); // TODO: Move cursor to the end of the text if (textLength > 0) { await this.clearWithDeletes(textLength); } return { success: true }; } catch (error) { return { success: false, error: "Failed to clear text" }; } }, { changeExpected: false, // TODO: can only make this true once we know for sure there was text in the text field tolerancePercent: 0.00, timeoutMs: 100, progress } ); }
  • TypeScript interface defining the return type of the clearText operation.
    export interface ClearTextResult { success: boolean; observation?: ObserveResult; error?: string; }

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/zillow/auto-mobile'

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