Skip to main content
Glama

browser_switch_to_frame

Switch to an iframe element on a webpage using locator strategies like ID, CSS, or XPath to interact with content inside embedded frames during web automation.

Instructions

Switches to an iframe element

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
byYesLocator strategy to find element
timeoutNoMaximum time to wait for element in milliseconds
valueYesValue for the locator strategy

Implementation Reference

  • Registration of the 'browser_switch_to_frame' tool with MCP server, including inline handler that delegates to ElementService.switchToFrame
    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}`, }, ], }; } } );
  • Inline handler function for the tool that executes the frame switch logic via service
    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}`, }, ], }; } }
  • Helper method in ElementService that implements the core logic: finds the iframe element and switches the driver context to it.
    async switchToFrame(params: LocatorParams): Promise<void> { const element = await this.findElement(params); await this.driver.switchTo().frame(element); }
  • Zod schema for locator parameters used in 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