playwright_press_key
Press keyboard keys during browser automation to simulate user input, interact with forms, navigate interfaces, or trigger actions in web applications.
Instructions
Press a keyboard key
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| key | Yes | Key to press (e.g. 'Enter', 'ArrowDown', 'a') | |
| selector | No | Optional CSS selector to focus before pressing key |
Implementation Reference
- src/tools/browser/interaction.ts:289-304 (handler)PressKeyTool class with execute method that optionally focuses a selector and presses the specified key using Playwright's page.keyboard.press.export class PressKeyTool extends BrowserToolBase { /** * Execute the key press tool */ async execute(args: any, context: ToolContext): Promise<ToolResponse> { return this.safeExecute(context, async (page) => { if (args.selector) { await page.waitForSelector(args.selector); await page.focus(args.selector); } await page.keyboard.press(args.key); return createSuccessResponse(`Pressed key: ${args.key}`); }); } }
- src/tools.ts:442-453 (schema)Input schema definition for the playwright_press_key tool, specifying parameters key (required) and optional selector.{ name: "playwright_press_key", description: "Press a keyboard key", inputSchema: { type: "object", properties: { key: { type: "string", description: "Key to press (e.g. 'Enter', 'ArrowDown', 'a')" }, selector: { type: "string", description: "Optional CSS selector to focus before pressing key" }, }, required: ["key"], }, },
- src/toolHandler.ts:647-648 (registration)Switch case in handleToolCall that dispatches to PressKeyTool.execute for executing the tool.case "playwright_press_key": return await pressKeyTool.execute(args, context);
- src/toolHandler.ts:417-417 (registration)Instantiation of PressKeyTool instance in initializeTools function.if (!pressKeyTool) pressKeyTool = new PressKeyTool(server);