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]
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It mentions waiting for visibility but lacks details on what happens on timeout (e.g., error or return), whether it polls continuously, or if it requires specific page states. This is a significant gap for a tool with potential side effects.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, clear sentence with no wasted words, making it highly concise and front-loaded. It efficiently communicates the core action without unnecessary elaboration.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the complexity of a waiting tool with 3 parameters, no annotations, and no output schema, the description is incomplete. It doesn't cover behavioral aspects like error handling, return values, or interaction with sibling tools, leaving critical gaps for an AI agent.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters2/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, so the description must compensate for undocumented parameters. It only implies the 'selector' parameter but doesn't explain 'page_id' (e.g., which page to wait on) or 'timeout' (e.g., default value or units), failing to add meaningful context beyond the schema.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose with a specific verb ('wait for') and resource ('element'), making it understandable. However, it doesn't explicitly differentiate from sibling tools like 'get_text' or 'click', which might also involve element visibility, so it misses the highest score.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. For example, it doesn't specify if this should be used before interacting with elements (e.g., before 'click' or 'type') or as a standalone check, leaving usage context unclear.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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