Skip to main content
Glama

playwright_click

Automate browser interactions by clicking elements on web pages using CSS selectors for testing and automation workflows.

Instructions

Click an element on the page using CSS selector

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
selectorYesCSS selector for element to click

Implementation Reference

  • The ClickToolHandler class implements the core logic for the 'playwright_click' tool. It clicks on the element matching the provided CSS selector using Playwright's page.locator().click() method.
    class ClickToolHandler(ToolHandler): @update_page_after_click async def handle(self, name: str, arguments: dict | None) -> list[types.TextContent | types.ImageContent | types.EmbeddedResource]: if not self._sessions: return [types.TextContent(type="text", text="No active session. Please create a new session first.")] session_id = list(self._sessions.keys())[-1] page = self._sessions[session_id]["page"] selector = arguments.get("selector") await page.locator(selector).click() return [types.TextContent(type="text", text=f"Clicked element with selector {selector}")]
  • The JSON schema defining the input for the 'playwright_click' tool, specifying a required 'selector' string parameter.
    types.Tool( name="playwright_click", description="Click an element on the page using CSS selector", inputSchema={ "type": "object", "properties": { "selector": {"type": "string", "description": "CSS selector for element to click"} }, "required": ["selector"] } ),
  • Registration of the 'playwright_click' tool handler in the tool_handlers dictionary, mapping the tool name to an instance of ClickToolHandler.
    "playwright_click": ClickToolHandler(),
  • Decorator applied to the click handler to automatically update the page reference after clicks that may trigger new page loads.
    def update_page_after_click(func): async def wrapper(self, name: str, arguments: dict | None): if not self._sessions: return [types.TextContent(type="text", text="No active session. Please create a new session first.")] session_id = list(self._sessions.keys())[-1] page = self._sessions[session_id]["page"] new_page_future = asyncio.ensure_future(page.context.wait_for_event("page", timeout=3000)) result = await func(self, name, arguments) try: new_page = await new_page_future await new_page.wait_for_load_state() self._sessions[session_id]["page"] = new_page except: pass # if page.url != self._sessions[session_id]["page"].url: # await page.wait_for_load_state() # self._sessions[session_id]["page"] = page return result return wrapper
  • The MCP server tool call handler that dispatches to the registered tool_handlers based on the tool name.
    @server.call_tool() async def handle_call_tool( name: str, arguments: dict | None ) -> list[types.TextContent | types.ImageContent | types.EmbeddedResource]: """ Handle tool execution requests. Tools can modify server state and notify clients of changes. """ if name in tool_handlers: return await tool_handlers[name].handle(name, arguments) else: raise ValueError(f"Unknown tool: {name}")

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/williamvd4/playwright-plus-python-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server