browser_clear
Clear input field values in web browsers using locator strategies like ID, CSS, or XPath to reset form fields or remove text from input elements.
Instructions
Clears the value of an input element
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| by | Yes | Locator strategy to find element | |
| timeout | No | Maximum time to wait for element in milliseconds | |
| value | Yes | Value for the locator strategy |
Implementation Reference
- src/tools/elementTools.ts:115-138 (registration)Registers the browser_clear tool, including its description, input schema (locatorSchema), and handler function that instantiates ElementService and calls clearElement.server.tool( 'browser_clear', 'Clears the value of an input element', { ...locatorSchema }, async ({ by, value, timeout = 15000 }) => { try { const driver = stateManager.getDriver(); const elementService = new ElementService(driver); await elementService.clearElement({ by, value, timeout }); return { content: [{ type: 'text', text: 'Element cleared' }], }; } catch (e) { return { content: [ { type: 'text', text: `Error clearing element: ${(e as Error).message}`, }, ], }; } } );
- src/types/index.ts:29-35 (schema)Zod schema defining the input parameters for browser_clear: locator strategy (by), value, and optional timeout.export const locatorSchema = { by: z .enum(['id', 'css', 'xpath', 'name', 'tag', 'class', 'link', 'partialLink']) .describe('Locator strategy to find element'), value: z.string().describe('Value for the locator strategy'), timeout: z.number().optional().describe('Maximum time to wait for element in milliseconds'), };
- src/services/elementService.ts:40-43 (handler)The core handler logic in ElementService.clearElement: finds the element using the locator and calls Selenium's clear() method on it.async clearElement(params: LocatorParams): Promise<void> { const element = await this.findElement(params); await element.clear(); }