Skip to main content
Glama

click_element

Click elements on web pages using CSS selectors to interact with buttons, links, or other interactive components in automated browser sessions.

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

TableJSON Schema
NameRequiredDescriptionDefault
selectorYes
contextNo

Implementation Reference

  • The core handler function for the 'click_element' tool. It is decorated with @mcp.tool() which serves as the registration mechanism in this MCP implementation. The function locates an element by CSS selector on the current browser page and clicks it, returning a success message or raising an error.
    @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}")

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