playwright_press_key
Press keyboard keys in browser automation to simulate user input, interact with web elements, and navigate pages using Playwright's browser control capabilities.
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:219-234 (handler)The PressKeyTool class contains the execute method that implements the core logic for the playwright_press_key tool: optionally focusing an element by selector and pressing the specified keyboard 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:399-410 (schema)The 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:546-547 (registration)Registration in the main tool handler switch statement: dispatches to PressKeyTool instance's execute method.case "playwright_press_key": return await pressKeyTool.execute(args, context);
- src/toolHandler.ts:346-346 (registration)Instantiation of the PressKeyTool instance used for handling the tool calls.if (!pressKeyTool) pressKeyTool = new PressKeyTool(server);
- src/tools.ts:470-470 (registration)The tool is listed in BROWSER_TOOLS array, used to determine if browser launch is required before execution."playwright_press_key",