6. Element Collections
6.1 Counting
Given an element collection, you can check how many elements were found by using the size method.
<html>
<body>
<div class="title">Title</div>
<div class="content">Content A</div>
<div class="content">Content B</div>
</body>
</html>
There are 3 div elements on the page.
browser.divs.size
#=> 3
With 2 of the div elements having the class “content”.
browser.divs(:class => 'content').size
#=> 2
Depending on your preferences, you can also use the method length instead of size.
browser.divs.length
#=> 3