click
Automate browser interactions by clicking on specific elements using a selector. Simplifies web automation tasks within the MCP server environment, enabling seamless control for automation workflows.
Instructions
Click on an element by selector
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| page_id | No | ||
| selector | Yes |
Input Schema (JSON Schema)
{
"properties": {
"page_id": {
"type": "string"
},
"selector": {
"type": "string"
}
},
"required": [
"selector"
],
"type": "object"
}
Implementation Reference
- src/playwright_mcp/server.py:237-244 (handler)Handler function for the 'click' tool. Extracts selector from arguments, validates it, retrieves the active page, executes page.click(selector), and returns a confirmation message.elif name == "click": selector = arguments.get("selector") if not selector: raise ValueError("Selector is required") page = get_active_page(arguments.get("page_id")) await page.click(selector) return [types.TextContent(type="text", text=f"Clicked element at selector: {selector}")]
- src/playwright_mcp/server.py:97-108 (schema)Tool schema definition for 'click', specifying input requirements: selector (required string), optional page_id.types.Tool( name="click", description="Click on an element by selector", inputSchema={ "type": "object", "properties": { "selector": {"type": "string"}, "page_id": {"type": "string"}, }, "required": ["selector"], }, ),
- src/playwright_mcp/server.py:80-198 (registration)Registration of the 'click' tool via the list_tools handler, which returns the list of available tools including 'click'.async def handle_list_tools() -> list[types.Tool]: """ List available Playwright browser automation tools. """ return [ types.Tool( name="navigate", description="Navigate to a URL", inputSchema={ "type": "object", "properties": { "url": {"type": "string"}, "page_id": {"type": "string"}, }, "required": ["url"], }, ), types.Tool( name="click", description="Click on an element by selector", inputSchema={ "type": "object", "properties": { "selector": {"type": "string"}, "page_id": {"type": "string"}, }, "required": ["selector"], }, ), 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"], }, ), types.Tool( name="get_text", description="Get text content from an element", inputSchema={ "type": "object", "properties": { "selector": {"type": "string"}, "page_id": {"type": "string"}, }, "required": ["selector"], }, ), types.Tool( name="get_page_content", description="Get the current page HTML content", inputSchema={ "type": "object", "properties": { "page_id": {"type": "string"}, }, }, ), types.Tool( name="take_screenshot", description="Take a screenshot of the current page", inputSchema={ "type": "object", "properties": { "page_id": {"type": "string"}, "selector": {"type": "string"}, }, }, ), types.Tool( name="new_page", description="Create a new browser page", inputSchema={ "type": "object", "properties": { "page_id": {"type": "string"}, }, "required": ["page_id"], }, ), types.Tool( name="switch_page", description="Switch to a different browser page", inputSchema={ "type": "object", "properties": { "page_id": {"type": "string"}, }, "required": ["page_id"], }, ), types.Tool( name="get_pages", description="List all available browser pages", inputSchema={ "type": "object", "properties": {}, }, ), 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"], }, ), ]