Skip to main content
Glama
blackwhite084

Playwright Server MCP

playwright_click

Automate web interactions by clicking elements using a CSS selector with Playwright Server MCP's web automation tool, simplifying page navigation and interaction tasks.

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 provides the core implementation for the 'playwright_click' tool. It retrieves the active page session, locates the element by CSS selector, clicks it using Playwright API, and returns a confirmation message.
    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}")]
  • Defines the JSON schema for the 'playwright_click' tool input, specifying a required 'selector' property of type string.
    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"] } ),
  • Registers the ClickToolHandler instance for the 'playwright_click' tool name in the global tool_handlers dictionary, which is used by the @server.call_tool() handler to dispatch tool calls.
    tool_handlers = { "playwright_navigate": NavigateToolHandler(), "playwright_screenshot": ScreenshotToolHandler(), "playwright_click": ClickToolHandler(), "playwright_fill": FillToolHandler(), "playwright_evaluate": EvaluateToolHandler(), "playwright_click_text": ClickTextToolHandler(), "playwright_get_text_content": GetTextContentToolHandler(), "playwright_get_html_content": GetHtmlContentToolHandler(), "playwright_new_session":NewSessionToolHandler(), }
  • Decorator applied to ClickToolHandler.handle() that listens for new page events after clicking (to handle navigation/frames) and updates the session's active page reference.
    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

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

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