type
Enter text into web form fields using CSS selectors to automate browser interactions for testing or data entry tasks.
Instructions
Type text into an input element
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| selector | Yes | ||
| text | Yes | ||
| page_id | No |
Implementation Reference
- src/playwright_mcp/server.py:246-255 (handler)Handler logic for the 'type' tool: validates arguments, gets the page, calls page.fill(selector, text), and returns a confirmation message.elif name == "type": selector = arguments.get("selector") text = arguments.get("text") if not selector or text is None: raise ValueError("Selector and text are required") page = get_active_page(arguments.get("page_id")) await page.fill(selector, text) return [types.TextContent(type="text", text=f"Typed '{text}' into {selector}")]
- src/playwright_mcp/server.py:109-121 (registration)Registration of the 'type' tool in the handle_list_tools() function, including name, description, and input schema.types.Tool( name="type", description="Type text into an input element", inputSchema={ "type": "object", "properties": { "selector": {"type": "string"}, "text": {"type": "string"}, "page_id": {"type": "string"}, }, "required": ["selector", "text"], }, ),
- src/playwright_mcp/server.py:112-120 (schema)Input schema definition for the 'type' tool, specifying required selector and text parameters.inputSchema={ "type": "object", "properties": { "selector": {"type": "string"}, "text": {"type": "string"}, "page_id": {"type": "string"}, }, "required": ["selector", "text"], },
- src/playwright_mcp/server.py:200-211 (helper)Helper function used by the 'type' handler to retrieve the active Playwright Page instance.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]