DocsElement Statebrowser_count_elements

browser_count_elements

browser_count_elements

Count the number of elements matching a CSS selector. Returns the count as an integer. Useful for checking how many items exist (e.g., list items, search results, table rows) without extracting full element data.

When to use browser_count_elements

Use browser_count_elements when you need to inspect the state, attributes, and geometry of page elements. It is part of Owl Browser's Element State toolset and runs inside a self-hosted, source-level stealth engine, so every call inherits the same undetectable browser fingerprint as the rest of your automation — no separate anti-detect setup required.

Usage Example

123456789101112
import asyncio
from owl_browser import OwlBrowser, RemoteConfig
# Async usage
async with OwlBrowser(config) as browser:
context = await browser.create_context()
context_id = context["context_id"]
await browser.count_elements(
context_id=context_id,
selector="#element-id"
)

Parameters

Required

context_idstringrequired

The unique identifier of the browser context (e.g., 'ctx_000001')

selectorstringrequired

CSS selector to count matching elements (e.g., 'li.item', 'input[type="text"]', 'table tr')

Response

Returns a JSON object with the operation result.

{
  "success": true,
  "result": <value>
}

Frequently Asked Questions

What does browser_count_elements do?

Count the number of elements matching a CSS selector. Returns the count as an integer. Useful for checking how many items exist (e.g., list items, search results, table rows) without extracting full element data. It belongs to Owl Browser's Element State category and is available through the REST API, the Python SDK (browser.count_elements()), the Node.js SDK, and the MCP server.

What parameters does browser_count_elements accept?

browser_count_elements accepts 2 required parameters (context_id, selector) and 0 optional parameters. All parameters are sent as JSON in a POST request to /api/execute/browser_count_elements.

Is browser_count_elements detectable by anti-bot systems like Cloudflare or DataDome?

No. browser_count_elements executes inside Owl Browser's Chromium engine, which applies fingerprint spoofing at the C++ source level rather than through JavaScript patches. Every tool call shares the same consistent, human-like fingerprint, so anti-bot systems such as Cloudflare, DataDome, and Akamai see an ordinary browser.

Related Tools

Browse the full Owl Browser API reference or get started with the Python SDK and Node.js SDK.