browser_blur_element
Remove focus from web elements to test form validation, improve accessibility, and simulate user interactions during automated browser testing.
Instructions
Remove focus from a specific element
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| by | Yes | Locator strategy to find element | |
| timeout | No | Maximum time to wait for element in milliseconds | |
| value | Yes | Value for the locator strategy |
Input Schema (JSON Schema)
{
"properties": {
"by": {
"description": "Locator strategy to find element",
"enum": [
"id",
"css",
"xpath",
"name",
"tag",
"class",
"link",
"partialLink"
],
"type": "string"
},
"timeout": {
"description": "Maximum time to wait for element in milliseconds",
"type": "number"
},
"value": {
"description": "Value for the locator strategy",
"type": "string"
}
},
"required": [
"by",
"value"
],
"type": "object"
}
Implementation Reference
- src/tools/actionTools.ts:458-481 (registration)Registers the 'browser_blur_element' tool with the MCP server, providing the input schema based on locatorSchema and a handler function that uses ActionService to perform the blur.server.tool( 'browser_blur_element', 'Remove focus from a specific element', { ...locatorSchema }, async ({ by, value }) => { try { const driver = stateManager.getDriver(); const actionService = new ActionService(driver); await actionService.blurElement({ by, value }); return { content: [{ type: 'text', text: `Removed focus from element` }], }; } catch (e) { return { content: [ { type: 'text', text: `Error removing focus from element: ${(e as Error).message}`, }, ], }; } } );
- src/services/actionService.ts:103-107 (handler)Executes the core logic for blurring an element by locating it via LocatorFactory and running JavaScript to call blur() on it.async blurElement(params: LocatorParams): Promise<void> { const locator = LocatorFactory.createLocator(params.by, params.value); const element = await this.driver.wait(until.elementLocated(locator), params.timeout || 15000); await this.driver.executeScript('arguments[0].blur();', element); }
- src/types/index.ts:29-35 (schema)Defines the Zod schema for locator parameters (by, value, timeout), spread into the 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'), };