Skip to main content
Glama

click_element

Execute clicks on web elements using CSS selectors to automate interactions within a headless browser environment via MCP Web Browser Server.

Instructions

Click an element on the current page. Args: selector: CSS selector for the element to click context: Optional context object for logging (ignored) Returns: Confirmation message or error details

Input Schema

NameRequiredDescriptionDefault
contextNo
selectorYes

Input Schema (JSON Schema)

{ "properties": { "context": { "anyOf": [ {}, { "type": "null" } ], "default": null, "title": "Context" }, "selector": { "title": "Selector", "type": "string" } }, "required": [ "selector" ], "title": "click_elementArguments", "type": "object" }

Implementation Reference

  • The main handler function for the 'click_element' tool, decorated with @mcp.tool() for registration. It uses Playwright to locate and click an element on the current page using the provided CSS selector.
    @mcp.tool() async def click_element( selector: str, context: Optional[Any] = None ) -> str: """ Click an element on the current page. Args: selector: CSS selector for the element to click context: Optional context object for logging (ignored) Returns: Confirmation message or error details """ global _current_page if not _current_page: raise ValueError("No page is currently loaded. Use browse_to first.") try: element = await _current_page.query_selector(selector) if not element: raise ValueError(f"No element found with selector: {selector}") await element.click() print(f"Clicked element: {selector}", file=sys.stderr) return f"Successfully clicked element: {selector}" except Exception as e: print(f"Error clicking element: {e}", file=sys.stderr) raise ValueError(f"Error clicking element: {e}")

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/random-robbie/mcp-web-browser'

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