Skip to main content
Glama

wait_for_selector

Wait for a web page element to become visible before proceeding with automation tasks, ensuring reliable interaction with dynamic content.

Instructions

Wait for an element to be visible on the page

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
selectorYes
page_idNo
timeoutNo

Implementation Reference

  • Handler implementation for the 'wait_for_selector' tool. Extracts selector and optional timeout/page_id from arguments, retrieves the page, and calls page.wait_for_selector with error handling.
    elif name == "wait_for_selector": selector = arguments.get("selector") if not selector: raise ValueError("Selector is required") timeout = arguments.get("timeout", 30000) # Default 30 seconds page = get_active_page(arguments.get("page_id")) try: await page.wait_for_selector(selector, timeout=timeout) return [types.TextContent(type="text", text=f"Element found: {selector}")] except Exception as e: return [types.TextContent(type="text", text=f"Timeout waiting for element: {selector}")]
  • Registration of the 'wait_for_selector' tool in the list_tools handler, including name, description, and input schema.
    types.Tool( name="wait_for_selector", description="Wait for an element to be visible on the page", inputSchema={ "type": "object", "properties": { "selector": {"type": "string"}, "page_id": {"type": "string"}, "timeout": {"type": "number"}, }, "required": ["selector"], }, ),
  • Helper function used by the handler to retrieve the active browser page based on page_id or default.
    def get_active_page(page_id: Optional[str] = None) -> Page: """Get the active page based on page_id or current default.""" global current_page_id if page_id is None: page_id = current_page_id if page_id not in pages: raise ValueError(f"Page not found: {page_id}") return pages[page_id]

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/misanthropic-ai/playwrite-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server