Skip to main content
Glama

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
NameRequiredDescriptionDefault
byYesLocator strategy to find element
valueYesValue for the locator strategy
timeoutNoMaximum time to wait for element in milliseconds

Implementation Reference

  • 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}`, }, ], }; } } );
  • 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); }
  • 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'), };

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