browser_type
Enter text into web page input fields using Selenium WebDriver for browser automation and testing.
Instructions
Type into an editable field
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 | |
| text | Yes | Text to enter into the element |
Implementation Reference
- src/tools/elementTools.ts:87-113 (registration)Registration of the 'browser_type' MCP tool. Includes input schema (extending locatorSchema with 'text' field) and the handler function that retrieves the WebDriver, instantiates ElementService, and calls sendKeysToElement.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/services/elementService.ts:29-33 (helper)Helper method in ElementService that implements the core typing logic: finds the target element using the locator, clears it, and sends the provided text 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); }
- src/types/index.ts:29-35 (schema)Base schema definition for element locators (by, value, timeout), which is spread into the browser_type tool's input schema.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'), };