How to Count Elements in Vibium
Count elements in Vibium with el.count() or len(findAll()). Runnable Python examples for counting rows, links, search results, and assertions.
To count elements in Vibium, call count() on a located element, like vibe.find("li").count(), which returns the number of matching nodes as an integer. This is the terse way to answer "how many of these are on the page?" — list items, table rows, links, search results, or cards. The equivalent is len(vibe.findAll("li")), which returns the same total by measuring the list that findAll() produces. Use count() when you only need the number, and findAll() when you also want to iterate over the actual Element objects to read their text, pull attributes, or click each one. Both work with CSS strings and with Vibium's semantic locators (role, text, label, placeholder, testid). Counting is one of the most common assertions in real test suites, where you verify that exactly N results, errors, or rows rendered after an action.
How do I count matching elements?
Locate the elements with find() and call count(), or call findAll() and take its length. Both return the same total.
from vibium import browser_sync as browser
vibe = browser.launch()
vibe.go("https://example.com/blog")
# Direct count
posts = vibe.find("article.post").count()
print(f"{posts} posts on this page")
# Equivalent: length of the findAll list
posts = len(vibe.findAll("article.post"))
print(f"{posts} posts on this page")
vibe.quit()count() is the lighter call when you only need the number, since it does not need to hand back every Element. Reach for len(findAll()) when you are about to loop over the matches anyway and want the count for free.
How do I count and then iterate over the results?
Use findAll() to get the list, count it with len(), and loop over the same list to read each element. This avoids querying the page twice.
from vibium import browser_sync as browser
vibe = browser.launch()
vibe.go("https://example.com/search?q=vibium")
results = vibe.findAll(".result")
print(f"Found {len(results)} results")
for r in results:
print(r.text())
vibe.quit()findAll() returns its matches as a list immediately rather than auto-waiting, and gives an empty list (length 0) when nothing matches. That makes it safe to count results that may legitimately be zero without raising an error.
How do I assert on a count in a test?
Read the count and compare it with ordinary Python. Since the return value is a normal integer, any assertion style works.
from vibium import browser_sync as browser
vibe = browser.launch()
vibe.go("https://example.com/cart")
assert vibe.find(".cart-item").count() == 3, "Cart should have 3 items"
# Range and emptiness checks read naturally too
assert vibe.find(".error").count() == 0
assert vibe.findAll("nav a") != []
vibe.quit()This keeps Vibium out of your way: there is no special matcher to learn, so counts slot straight into pytest, unittest, or whatever framework you already use. If the count depends on content that loads after the page, wait for at least one element with waitFor() before counting so you do not measure too early.
Next steps
Frequently asked questions
How do I count elements in Vibium?
Call count() on a located element, like vibe.find('li').count(), which returns the number of nodes matching that selector as an integer. You can also use len() on the list returned by findAll(), for example len(vibe.findAll('li')), which gives the same total.
What is the difference between count() and findAll() in Vibium?
count() returns just the number of matches as an integer, while findAll() returns the actual list of Element objects you can loop over. Use count() when you only need the total, and findAll() when you also need to read text, attributes, or click each element.
How do I assert the number of results in Vibium?
Read the count and compare it in plain Python, for example assert vibe.find('.result').count() == 10. Because count() returns a normal integer, you can use any assertion library or framework you already use, with no Vibium-specific matcher required for the check.
Vibium is created by Jason Huggins. This is an independent tutorial — see the official Vibium site and GitHub repo for canonical docs.
Related guides
How to Check a Checkbox in Vibium
Check a checkbox in Vibium with el.check(). Runnable Python examples for ticking, unticking, verifying state, and handling many checkboxes.
3 min read→Commands & APIHow to Clear an Input Field in Vibium
Clear an input field in Vibium with el.clear(). Runnable Python examples for emptying text fields, replacing values, and resetting forms.
2 min read→Commands & APIHow to Click Elements in Vibium
Click buttons and links in Vibium with el.click(). Runnable Python examples plus how auto-waiting and actionability make clicks reliable.
2 min read→Commands & APIHow to Double-Click in Vibium
Double-click elements in Vibium with el.dblclick(). Runnable Python examples for rows and inline edits, plus how auto-waiting keeps clicks reliable.
3 min read→