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
| Name | Required | Description | Default |
|---|---|---|---|
| page_id | No | ||
| selector | Yes | ||
| timeout | No |
Input Schema (JSON Schema)
{
"properties": {
"page_id": {
"type": "string"
},
"selector": {
"type": "string"
},
"timeout": {
"type": "number"
}
},
"required": [
"selector"
],
"type": "object"
}
Implementation Reference
- src/playwright_mcp/server.py:324-337 (handler)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}")]
- src/playwright_mcp/server.py:185-197 (registration)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"], }, ),