browser_iframe_click
Interact with elements inside iframes using this tool. It automates clicks on specific elements within iframes, simplifying web automation and scraping tasks on protected sites with anti-bot measures.
Instructions
Click an element inside an iframe on the page
Args:
iframeSelector: The selector of the iframe - required
selector: The selector of the element to click - required
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| iframeSelector | Yes | ||
| selector | Yes |
Implementation Reference
- The handler function for browser_iframe_click tool. It validates inputs, switches to the specified iframe using Selenium, clicks the target element by CSS selector, switches back to default content, and returns a success response. Registered as an MCP tool via the @mcp.tool() decorator.@mcp.tool() async def browser_iframe_click( iframeSelector: str, selector: str, ): """Click an element inside an iframe on the page Args: iframeSelector: The selector of the iframe - required selector: The selector of the element to click - required """ assert iframeSelector, "Iframe selector is required" assert selector, "Selector is required" async def iframe_click_handler(driver: uc.Chrome): iframe = driver.find_element(By.CSS_SELECTOR, iframeSelector) driver.switch_to.frame(iframe) driver.find_element(By.CSS_SELECTOR, selector).click() driver.switch_to.default_content() return await create_success_response( f"Clicked element {selector} inside iframe {iframeSelector}" ) return await tool.safe_execute( ToolContext(webdriver=await ensure_browser()), iframe_click_handler )