Package com.codeborne.selenide
Class ElementsCollection
java.lang.Object
com.codeborne.selenide.ElementsCollection
-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionElementsCollection(Driver driver, String cssSelector) ElementsCollection(Driver driver, Collection<? extends org.openqa.selenium.WebElement> elements) ElementsCollection(Driver driver, org.openqa.selenium.By seleniumSelector) ElementsCollection(CollectionSource collection) -
Method Summary
Modifier and TypeMethodDescriptionGive this collection a human-readable nameReturns a "dynamic"Iterablewhich reloads web elements during iteration.Returns a "static"Iterablewhich doesn't reload web elements during iteration.attributes(String attribute) Gets all the specific attribute values in elements collectionexclude(WebElementCondition condition) Filters elements excluding those which met the given condition (lazy evaluation)excludeWith(WebElementCondition condition) Filters elements excluding those which met the given condition (lazy evaluation)filter(WebElementCondition condition) Filters collection elements based on the given condition (lazy evaluation)filterBy(WebElementCondition condition) Filters collection elements based on the given condition (lazy evaluation)find(WebElementCondition condition) Find the first element which met the given condition (lazy evaluation)findBy(WebElementCondition condition) Find the first element which met the given condition (lazy evaluation)first()returns the first element of the collection (lazy evaluation)first(int elements) returns the first n elements of the collection (lazy evaluation)get(int index) Gets the n-th element of collection (lazy evaluation)last()returns the last element of the collection (lazy evaluation)last(int elements) returns the last n elements of the collection (lazy evaluation)should(CollectionCondition... conditions) Check if a collection matches given condition(s).should(CollectionCondition condition, Duration timeout) Check if a collection matches a given condition within the given time period.protected ElementsCollectionshould(String prefix, Duration timeout, CollectionCondition... conditions) shouldBe(CollectionCondition... conditions) For example:$$(".error").shouldBe(empty)shouldBe(CollectionCondition condition, Duration timeout) shouldHave(CollectionCondition... conditions) For example:$$(".error").shouldHave(size(3))$$(".error").shouldHave(texts("Error1", "Error2"))shouldHave(CollectionCondition condition, Duration timeout) Check if a collection matches given condition within given periodintsize()return actual size of the collection, doesn't wait on collection to be loaded.snapshot()Takes the snapshot of current state of this collection.texts()Gets all the texts in elements collectiontoString()protected voidwaitUntil(CollectionCondition condition, Duration timeout)
-
Constructor Details
-
ElementsCollection
-
ElementsCollection
public ElementsCollection(Driver driver, Collection<? extends org.openqa.selenium.WebElement> elements) -
ElementsCollection
-
ElementsCollection
-
-
Method Details
-
should
Check if a collection matches given condition(s).For example:
$$(".text_list").should(containExactTextsCaseSensitive("text1", "text2")); $$(".cat_list").should(allMatch("value==cat", el -> el.getAttribute("value").equals("cat"))); -
should
Check if a collection matches a given condition within the given time period.- Parameters:
timeout- maximum waiting time
-
shouldBe
For example:$$(".error").shouldBe(empty) -
shouldBe
-
shouldHave
For example:$$(".error").shouldHave(size(3))$$(".error").shouldHave(texts("Error1", "Error2")) -
shouldHave
Check if a collection matches given condition within given period- Parameters:
timeout- maximum waiting time
-
should
@Nonnull protected ElementsCollection should(String prefix, Duration timeout, CollectionCondition... conditions) -
waitUntil
-
filter
Filters collection elements based on the given condition (lazy evaluation)- Parameters:
condition- condition- Returns:
- ElementsCollection
- See Also:
-
filterBy
Filters collection elements based on the given condition (lazy evaluation)- Parameters:
condition- condition- Returns:
- ElementsCollection
- See Also:
-
exclude
Filters elements excluding those which met the given condition (lazy evaluation)- Parameters:
condition- condition- Returns:
- ElementsCollection
- See Also:
-
excludeWith
Filters elements excluding those which met the given condition (lazy evaluation)- Parameters:
condition- condition- Returns:
- ElementsCollection
- See Also:
-
find
Find the first element which met the given condition (lazy evaluation)- Parameters:
condition- condition- Returns:
- SelenideElement
- See Also:
-
findBy
Find the first element which met the given condition (lazy evaluation)- Parameters:
condition- condition- Returns:
- SelenideElement
- See Also:
-
texts
Gets all the texts in elements collection- See Also:
-
- NOT RECOMMENDED
Instead of just getting texts, we highly recommend to verify them with
$$.shouldHave(texts(...));.
- NOT RECOMMENDED
Instead of just getting texts, we highly recommend to verify them with
-
attributes
Gets all the specific attribute values in elements collection- See Also:
-
- NOT RECOMMENDED
Instead of just getting attributes, we highly recommend to verify them with
$$.shouldHave(attributes(...));.
- NOT RECOMMENDED
Instead of just getting attributes, we highly recommend to verify them with
-
get
Gets the n-th element of collection (lazy evaluation)- Parameters:
index- 0..N- Returns:
- the n-th element of collection
- See Also:
-
first
returns the first element of the collection (lazy evaluation)
NOTICE: Instead of
$$(css).first(), prefer$(css)as it's faster and returns the same result- Returns:
- the first element of the collection
- See Also:
-
last
returns the last element of the collection (lazy evaluation)- Returns:
- the last element of the collection
- See Also:
-
first
returns the first n elements of the collection (lazy evaluation)- Parameters:
elements- number of elements 1…N- See Also:
-
last
returns the last n elements of the collection (lazy evaluation)- Parameters:
elements- number of elements 1…N- See Also:
-
size
@CheckReturnValue public int size()return actual size of the collection, doesn't wait on collection to be loaded.
- Returns:
- actual size of the collection
- See Also:
-
snapshot
Takes the snapshot of current state of this collection. Succeeding calls to this object WILL NOT RELOAD collection element from browser.Use it to speed up your tests - but only if you know that collection will not be changed during the test.
- Returns:
- current state of this collection
- See Also:
-
asFixedIterable
Returns a "static"Iterablewhich doesn't reload web elements during iteration. It's faster thanasDynamicIterable()}, but can sometimes can causeStaleElementReferenceExceptionetc. if elements are re-rendered during the iteration.- Since:
- 6.2.0
- See Also:
-
asDynamicIterable
Returns a "dynamic"Iterablewhich reloads web elements during iteration. It's slower thanasFixedIterable(), but helps to avoidStaleElementReferenceExceptionetc.- Since:
- 6.2.0
- See Also:
-
as
Give this collection a human-readable nameCaution: you probably don't need this method. It's always a good idea to have the actual selector instead of "nice" description (which might be misleading or even lying).
- Parameters:
alias- a human-readable name of this collection (null or empty string not allowed)- Returns:
- this collection
- Since:
- 5.20.0
-
toString
-