Skip to main content
Glama
Lokii0911
by Lokii0911

find_element

Locate a web element using CSS, XPath, or other selectors and return a compact summary with details like tag, text, and attributes.

Instructions

Find an element and return a compact summary of it.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
strategyYes
valueYes
timeout_secondsNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • Handler implementation: finds a web element using the given strategy/value and returns a compact ElementSummary.
    def find_element(
        self,
        strategy: LocatorStrategy,
        value: str,
        timeout_seconds: float | None = None,
    ) -> ElementSummary:
        with self._lock:
            element = self._wait_for_element(strategy, value, timeout_seconds)
            return self._summarize_element(element)
  • MCP tool registration: decorator @mcp.tool() that exposes find_element as an MCP tool, delegating to browser.find_element.
    @mcp.tool()
    def find_element(
        strategy: LocatorStrategy,
        value: str,
        timeout_seconds: float | None = None,
    ) -> dict[str, Any]:
        """Find an element and return a compact summary of it."""
        return _run("find_element", browser.find_element, strategy, value, timeout_seconds)
  • Output schema: ElementSummary Pydantic model returned by find_element handler.
    class ElementSummary(BaseModel):
        tag_name: str
        text: str
        enabled: bool
        displayed: bool
        selected: bool
        attributes: dict[str, Any] = Field(default_factory=dict)
  • Input schema: LocatorStrategy type alias defining valid locator strategies for find_element.
    LocatorStrategy = Literal[
        "id",
        "name",
        "css selector",
        "xpath",
        "link text",
        "partial link text",
        "tag name",
        "class name",
    ]
  • Helper: waits for element to be present (default), visible, or clickable using Selenium expected conditions and LOCATOR_MAP.
    def _wait_for_element(
        self,
        strategy: LocatorStrategy,
        value: str,
        timeout_seconds: float | None,
        *,
        clickable: bool = False,
        visible: bool = True,
    ) -> WebElement:
        driver = self._require_driver()
        by = LOCATOR_MAP[strategy]
        timeout = timeout_seconds if timeout_seconds is not None else self._settings.page_load_timeout_seconds
        condition = EC.presence_of_element_located((by, value))
        if clickable:
            condition = EC.element_to_be_clickable((by, value))
        elif visible:
            condition = EC.visibility_of_element_located((by, value))
        try:
            return WebDriverWait(driver, timeout).until(condition)
        except TimeoutException as exc:
            raise BrowserError(f"Element not found: {strategy}={value}") from exc
    
    def _summarize_element(self, element: WebElement) -> ElementSummary:
        attributes = self._require_driver().execute_script(
            """
            const el = arguments[0];
            const attrs = {};
            for (const attr of el.attributes) attrs[attr.name] = attr.value;
            return attrs;
            """,
            element,
        )
        return ElementSummary(
            tag_name=element.tag_name,
            text=element.text,
            enabled=element.is_enabled(),
            displayed=element.is_displayed(),
            selected=element.is_selected(),
            attributes=attributes or {},
        )
Behavior1/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations provided; the description does not disclose behavior for timeouts, missing elements, or return format. It says 'return a compact summary' without details.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness2/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single sentence but lacks necessary detail, making it under-specification rather than concise.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness1/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Despite having an output schema, the description does not explain the return format. For a tool that returns a summary, this is a major gap. Also, no mention of element interaction context.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters1/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, and the description adds no parameter information. The three parameters (strategy, value, timeout_seconds) are not explained.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose3/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description states the tool finds an element and returns a compact summary, but 'compact summary' is vague. It does not distinguish from sibling tools like 'get_text' or 'wait_for_element'.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance on when to use this tool versus alternatives such as 'get_text' or 'get_attribute'. The description lacks usage context.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other 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/Lokii0911/SeleniumMCP'

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