playwright_click_text
Click web page elements by matching their text content for automated interaction during browser testing or web scraping tasks.
Instructions
Click an element on the page by its text content
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| text | Yes | Text content of the element to click |
Implementation Reference
- src/playwright_server/server.py:270-279 (handler)The ClickTextToolHandler class provides the core implementation of the playwright_click_text tool. Its handle method clicks on the first visible element matching the given text using Playwright's text locator.class ClickTextToolHandler(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"] text = arguments.get("text") await page.locator(f"text={text}").nth(0).click() return [types.TextContent(type="text", text=f"Clicked element with text {text}")]
- JSON Schema definition for the playwright_click_text tool, specifying the required 'text' parameter.types.Tool( name="playwright_click_text", description="Click an element on the page by its text content", inputSchema={ "type": "object", "properties": { "text": {"type": "string", "description": "Text content of the element to click"} }, "required": ["text"] } ),
- src/playwright_server/server.py:340-340 (registration)Registration of the ClickTextToolHandler instance in the tool_handlers dictionary, which maps tool names to their handlers for execution via handle_call_tool."playwright_click_text": ClickTextToolHandler(),