The object of this class is also a "proxy", the same way as object of SelenideElement class. This object can be created by calling the
$$ method and represents the list of web-elements on the page.
The following types of methods are defined for ElementsCollection:
- methods-selectors of specific collection elements
- more precisely - the methods that create proxy objects representing selected collection elements
- methods to check the state of elements collection - Assertions
- methods to get statues and attributes of elements collection
Trigger the search of the actual elements on the page for the proxy-collection, performs the check based on collection condition (an object of CollectionCondition class), and return back the object of ElementsCollection class (i.e. proxy-collection) again, allowing to build chains of further methods calls.
$$("#mytable tbody tr").shouldHave(size(2))
ElementsCollection assertions also play role of explicit waits. They wait for condition (e.g.
texts("a", "b", "c")) to be satisfied until timeout reached (the value of
Configuration.collectionsTimeout that is set to 6000 ms by default).
Methods to get statues and attributes of elements collection
Trigger the actual search of elements on the page for the proxy-collection, and return the corresponding value:
size()// triggers the actual search only for first call of size(), in order to get the actual size second time the actual search should be re-initiated by some other method e.g.
getTexts()// returns the array of visible elements collection texts, e.g. for elements:
<li>a</li><li hidden>b</li><li>c</li>will return the array
["a", "", "c"]
This methods do not have built-in implicit waits.
Methods-selectors of specific collection elements
Additional filtering - returns the proxy-collection that represents elements of original collection filtered by condition, does not have built in implicit waits:
filterBy(Condition)- returns collection (as ElementsCollection) with only those original collection elements that satisfies the condition, e.g.
Additional element search - returns the proxy-element that represent found element from original collection, does not have built in implicit waits:
get(int)- returns nth element (as
SelenideElement); on any subsequent action on the element the implicit waiting for visibility of nth collection element will be triggered.
findBy(Condition)- returns the first collection element (as
SelenideElement) that satisfied the condition; on any subsequent action on the found element the implicit waiting for visibility of specified collection element will be triggered.
Additional filtering and search allows almost completely refuse to use less readable xpath locators:
$$("#list li").filterBy(cssClass("enabled")).findBy(exactText("foo")).find(".remove").click(); // instead of $(By.xpath("//*[@id='list']//li[@class='enabled' and .//text()='foo']//*[@class='remove']")).click();