Skip to main content
Glama

wait_for_selector

Ensure a specific element is visible on a webpage by specifying a CSS selector and optional timeout. Automates browser interactions efficiently for testing and automation workflows.

Instructions

Wait for an element to be visible on the page

Input Schema

NameRequiredDescriptionDefault
page_idNo
selectorYes
timeoutNo

Input Schema (JSON Schema)

{ "properties": { "page_id": { "type": "string" }, "selector": { "type": "string" }, "timeout": { "type": "number" } }, "required": [ "selector" ], "type": "object" }

Implementation Reference

  • Executes the wait_for_selector tool: retrieves selector and optional timeout/page_id, uses get_active_page to get the page, then calls page.wait_for_selector, returning success or timeout message.
    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}")]
  • Registers the wait_for_selector tool in the list_tools handler, defining its name, description, and input schema (selector required, optional page_id and timeout).
    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"], }, ),

Other Tools

Related 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