Find Elements
find_elementsFind matching elements via CSS or XPath selectors and get structured data: count, tag names, text, and optional outer HTML. Useful for verifying element presence and inspecting multiple matches.
Instructions
Find matching elements and return structured element information.
Use this tool when you need to discover how many elements match a selector, inspect their text/tag names, or inspect the HTML of multiple matches.
This tool converts matching elements into ordinary serializable dictionaries. It does not return live SeleniumBase element objects.
Args:
selector: A CSS selector, or an XPath selector that SeleniumBase can
convert to CSS. In sb.find_elements, SeleniumBase automatically
attempts to convert XPath to CSS. Some XPath expressions, such
as those using contains(...), cannot be converted to CSS and
therefore aren't supported by this tool.
timeout: Maximum number of seconds to wait for at least one matching
element to appear. If the selector is an XPath selector that
cannot be converted into a valid CSS selector, then the wait
might be less than the timeout.
include_html: If True, include each matching element's outer HTML.
If False, return only tag name and text.Returns: A dictionary containing: - count: Number of matching elements found. - matches: A list of element dictionaries containing tag_name and text, plus html when include_html=True. If there's an error during search, then "error" is added into the returned dictionary with error details.
Tool selection: - Need structured information about matching elements -> use find_elements. - Need the visible text/HTML of a page or a single element -> use get_content. - Need to click one of several matches -> use click_element with nth. - Need to know whether an element is present/visible -> use check_if_condition.
Notes: Element handles cannot be persisted across MCP calls. If you find elements and then need to act on one, resolve it again with the appropriate interaction tool.
For uncaught errors, @handle_sb_errors returns strings.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| timeout | No | ||
| selector | Yes | ||
| include_html | No |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |