browser_clear
Clears input field values in web browsers for automated testing and form resetting. Use this Selenium WebDriver tool to remove text from text boxes, search bars, and form inputs during browser automation.
Instructions
Clears the value of an input element
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| by | Yes | Locator strategy to find element | |
| value | Yes | Value for the locator strategy | |
| timeout | No | Maximum time to wait for element in milliseconds |
Implementation Reference
- src/tools/elementTools.ts:115-137 (registration)Registration of the 'browser_clear' tool, including the inline handler function that invokes ElementService.clearElement to clear the input element.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)Schema definition for locators used as input parameters for the browser_clear tool (by, value, 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)Core handler logic for clearing the element using Selenium WebDriver's element.clear() method.async clearElement(params: LocatorParams): Promise<void> { const element = await this.findElement(params); await element.clear(); }