Skip to main content
Glama

browser.find_elements

Locate multiple web elements using CSS selectors to extract text, links, values, positions, and visibility for automation tasks like scraping or interaction.

Instructions

Find all elements matching a CSS selector and return their text, href, value, bounding box, and visibility. Useful before clicking or scraping multiple items.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
session_idYes
selectorYes
limitNo

Implementation Reference

  • The _find_elements handler executes JavaScript in the current Playwright page context to find elements matching a CSS selector and return their attributes.
    async def _find_elements(self, payload: FindElementsInput) -> dict[str, Any]:
        session = await self.manager.get_session(payload.session_id)
        elements = await session.page.evaluate(
            """([selector, limit]) => {
                const els = [...document.querySelectorAll(selector)].slice(0, limit);
                return els.map(el => {
                    const r = el.getBoundingClientRect();
                    return {
                        tag: el.tagName.toLowerCase(),
                        text: el.innerText?.substring(0, 200) || '',
                        value: el.value || null,
                        href: el.href || null,
                        id: el.id || null,
                        class: el.className || null,
                        visible: r.width > 0 && r.height > 0,
                        x: Math.round(r.x), y: Math.round(r.y),
                        width: Math.round(r.width), height: Math.round(r.height),
                    };
                });
            }""",
            [payload.selector, payload.limit],
        )
        return {"session_id": payload.session_id, "selector": payload.selector, "elements": elements}
  • The FindElementsInput Pydantic model defines the input schema for the browser.find_elements tool.
    class FindElementsInput(SessionIdInput):
        selector: str = Field(min_length=1, max_length=2000)
        limit: int = Field(default=20, ge=1, le=100)
  • Registration of the browser.find_elements tool in the McpToolGateway, mapping its name, description, input schema, and handler.
        name="browser.find_elements",
        description=(
            "Find all elements matching a CSS selector and return their "
            "text, href, value, bounding box, and visibility. "
            "Useful before clicking or scraping multiple items."
        ),
        input_model=FindElementsInput,
        handler=self._find_elements,
    ),
Behavior3/5

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

With no annotations provided, the description carries the full burden. It successfully discloses return data fields, but fails to declare safety properties (read-only vs destructive), error behavior (empty array vs null on no matches), or pagination/limiting behavior beyond the parameter existing.

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

Conciseness5/5

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

Two well-structured sentences with zero waste. First sentence front-loads the core action and return value details; second provides usage context. Every word earns its place.

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

Completeness3/5

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

For a 3-parameter tool without output schema, listing the return fields is helpful, but the description should clarify the return structure (array format) and handling of zero matches. Omits session lifecycle context present in sibling tools.

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

Parameters3/5

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

Schema coverage is 0%, requiring the description to compensate. It explains 'selector' via 'CSS selector' context, but provides no guidance on 'session_id' (despite being required) or 'limit' (beyond the schema's default value). Adequate but incomplete given the coverage gap.

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

Purpose5/5

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

Excellent specificity: states the exact action ('Find'), resource ('elements'), mechanism ('CSS selector'), and return fields ('text, href, value, bounding box, and visibility'). The mention of 'CSS selector' clearly distinguishes it from sibling tool 'find_by_vision' which likely uses visual/AI matching.

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

Usage Guidelines3/5

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

Provides implied context ('Useful before clicking or scraping'), suggesting when to use it, but lacks explicit guidance on when NOT to use it (e.g., vs 'wait_for_selector' for synchronization) or direct comparison to alternatives like 'find_by_vision' or 'observe'.

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/LvcidPsyche/auto-browser'

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