Skip to main content
Glama

get_text

Extract text content from a specific web element using a selector, enabling precise data retrieval for browser automation tasks in the Playwright MCP environment.

Instructions

Get text content from an element

Input Schema

NameRequiredDescriptionDefault
page_idNo
selectorYes

Input Schema (JSON Schema)

{ "properties": { "page_id": { "type": "string" }, "selector": { "type": "string" } }, "required": [ "selector" ], "type": "object" }

Implementation Reference

  • The main handler for the 'get_text' tool within the handle_call_tool function. Retrieves text content from the element specified by selector on the active page using Playwright's text_content method.
    elif name == "get_text": selector = arguments.get("selector") if not selector: raise ValueError("Selector is required") page = get_active_page(arguments.get("page_id")) text = await page.text_content(selector) return [types.TextContent(type="text", text=text or "")]
  • Registers the 'get_text' tool in the list_tools handler, defining its name, description, and input schema (requires 'selector', optional 'page_id').
    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(
  • Helper function used by the get_text handler (and others) to obtain the Page instance for the specified or current page_id.
    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]

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/misanthropic-ai/playwrite-mcp'

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