browser_key_press
Press keyboard keys during web browser automation to interact with web elements, submit forms, navigate interfaces, and perform keyboard shortcuts in automated testing workflows.
Instructions
Press a key on the keyboard
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| key | Yes | Key to press (e.g., 'Enter', 'Tab', 'a', etc.) |
Implementation Reference
- src/tools/actionTools.ts:203-228 (registration)Registers the 'browser_key_press' tool using server.tool(), defines input schema for 'key', and provides the handler function that instantiates ActionService and calls pressKey(key).server.tool( 'browser_key_press', 'Press a key on the keyboard', { key: z.string().describe("Key to press (e.g., 'Enter', 'Tab', 'a', etc.)"), }, async ({ key }) => { try { const driver = stateManager.getDriver(); const actionService = new ActionService(driver); await actionService.pressKey(key); return { content: [{ type: 'text', text: `Key '${key}' pressed` }], }; } catch (e) { return { content: [ { type: 'text', text: `Error pressing key: ${(e as Error).message}`, }, ], }; } } );
- src/services/actionService.ts:60-63 (handler)The core handler logic for pressing a key, using Selenium WebDriver actions to perform keyDown and keyUp on the specified key.async pressKey(key: string): Promise<void> { const actions = this.driver.actions({ bridge: true }); await actions.keyDown(key).keyUp(key).perform(); }
- src/tools/actionTools.ts:207-208 (schema)Zod schema defining the input parameter 'key' as a string.key: z.string().describe("Key to press (e.g., 'Enter', 'Tab', 'a', etc.)"), },