browser_switch_to_frame
Switch to an iframe element in web automation by specifying a locator strategy and value, enabling interaction with embedded content.
Instructions
Switches to an iframe element
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| by | Yes | Locator strategy to find element | |
| value | Yes | Value for the locator strategy | |
| timeout | No | Maximum time to wait for element in milliseconds |
Implementation Reference
- src/tools/elementTools.ts:294-317 (registration)Registers the 'browser_switch_to_frame' tool with the MCP server, including input schema from locatorSchema and an async handler that instantiates ElementService and calls switchToFrame on it.server.tool( 'browser_switch_to_frame', 'Switches to an iframe element', { ...locatorSchema }, async ({ by, value, timeout = 15000 }) => { try { const driver = stateManager.getDriver(); const elementService = new ElementService(driver); await elementService.switchToFrame({ by, value, timeout }); return { content: [{ type: 'text', text: 'Switched to iframe' }], }; } catch (e) { return { content: [ { type: 'text', text: `Error switching to frame: ${(e as Error).message}`, }, ], }; } } );
- src/services/elementService.ts:77-80 (handler)Core implementation of frame switching: locates the iframe element using the provided locator and switches the WebDriver context to that frame.async switchToFrame(params: LocatorParams): Promise<void> { const element = await this.findElement(params); await this.driver.switchTo().frame(element); }
- src/types/index.ts:29-35 (schema)Zod schema definition for the tool's input parameters (locator strategy, value, optional 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'), };