browser_type
Enter text into web form fields using various locator strategies to automate data input during browser automation tasks.
Instructions
Type into an editable field
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| by | Yes | Locator strategy to find element | |
| text | Yes | Text to enter into the element | |
| timeout | No | Maximum time to wait for element in milliseconds | |
| value | Yes | Value for the locator strategy |
Implementation Reference
- src/tools/elementTools.ts:87-113 (registration)Registration of the browser_type tool, including inline handler that delegates to ElementService.sendKeysToElement and error handling.server.tool( 'browser_type', 'Type into an editable field', { ...locatorSchema, text: z.string().describe('Text to enter into the element'), }, async ({ by, value, text, timeout = 15000 }) => { try { const driver = stateManager.getDriver(); const elementService = new ElementService(driver); await elementService.sendKeysToElement({ by, value, text, timeout }); return { content: [{ type: 'text', text: `Text "${text}" entered into element` }], }; } catch (e) { return { content: [ { type: 'text', text: `Error entering text: ${(e as Error).message}`, }, ], }; } } );
- src/tools/elementTools.ts:90-93 (schema)Input schema for browser_type tool: locator params plus 'text' field.{ ...locatorSchema, text: z.string().describe('Text to enter into the element'), },
- src/types/index.ts:29-35 (schema)Base locatorSchema used in browser_type and other element tools.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:29-33 (helper)Helper method in ElementService that implements the core typing logic: find element, clear it, and send keys using Selenium WebDriver.async sendKeysToElement(params: LocatorParams & { text: string }): Promise<void> { const element = await this.findElement(params); await element.clear(); await element.sendKeys(params.text); }