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
| Name | Required | Description | Default |
|---|---|---|---|
| session_id | Yes | ||
| selector | Yes | ||
| limit | No |
Implementation Reference
- controller/app/tool_gateway.py:1175-1198 (handler)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) - controller/app/tool_gateway.py:692-700 (registration)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, ),