Skip to main content
Glama

browser_key_press

Simulate keyboard key presses during web automation to interact with forms, navigate pages, or trigger browser actions using Selenium WebDriver.

Instructions

Press a key on the keyboard

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
keyYesKey to press (e.g., 'Enter', 'Tab', 'a', etc.)

Implementation Reference

  • Registers the 'browser_key_press' MCP tool with server.tool(), including input schema for 'key' parameter and the handler function that retrieves the WebDriver, instantiates ActionService, calls pressKey(key), and returns success/error messages.
    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}`,
              },
            ],
          };
        }
      }
    );
  • Implements the core key press functionality in ActionService using Selenium WebDriver's ActionSequence: keyDown(key) followed by keyUp(key).
    async pressKey(key: string): Promise<void> {
      const actions = this.driver.actions({ bridge: true });
      await actions.keyDown(key).keyUp(key).perform();
    }
  • Zod schema defining the input parameter 'key' as a string for the browser_key_press tool.
    {
      key: z.string().describe("Key to press (e.g., 'Enter', 'Tab', 'a', etc.)"),
    },

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/pshivapr/selenium-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server