browser_focus_element
Focus on specific web elements using locator strategies like ID, CSS, or XPath for precise browser automation and testing interactions.
Instructions
Focus on a specific element
Input Schema
TableJSON 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 |
Implementation Reference
- src/tools/actionTools.ts:438-456 (registration)Registration of the 'browser_focus_element' tool, including the inline handler function that executes the tool logic by delegating to ActionService.server.tool('browser_focus_element', 'Focus on a specific element', { ...locatorSchema }, async ({ by, value }) => { try { const driver = stateManager.getDriver(); const actionService = new ActionService(driver); await actionService.focusElement({ by, value }); return { content: [{ type: 'text', text: `Focused on element` }], }; } catch (e) { return { content: [ { type: 'text', text: `Error focusing on element: ${(e as Error).message}`, }, ], }; } });
- src/tools/actionTools.ts:438-456 (handler)The handler function for the tool, which handles input, calls the service, and returns response.server.tool('browser_focus_element', 'Focus on a specific element', { ...locatorSchema }, async ({ by, value }) => { try { const driver = stateManager.getDriver(); const actionService = new ActionService(driver); await actionService.focusElement({ by, value }); return { content: [{ type: 'text', text: `Focused on element` }], }; } catch (e) { return { content: [ { type: 'text', text: `Error focusing on element: ${(e as Error).message}`, }, ], }; } });
- src/types/index.ts:29-35 (schema)Zod schema for locator parameters used in the tool input validation.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'), };
- src/services/actionService.ts:97-101 (helper)Core implementation of focusing an element using Selenium WebDriver executeScript.async focusElement(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].focus();', element); }