Package com.codeborne.selenide
Class ElementsCollection
- java.lang.Object
-
- java.util.AbstractCollection<E>
-
- java.util.AbstractList<SelenideElement>
-
- com.codeborne.selenide.ElementsCollection
-
- All Implemented Interfaces:
java.lang.Iterable<SelenideElement>
,java.util.Collection<SelenideElement>
,java.util.List<SelenideElement>
@ParametersAreNonnullByDefault public class ElementsCollection extends java.util.AbstractList<SelenideElement>
-
-
Constructor Summary
Constructors Constructor Description ElementsCollection(Driver driver, java.lang.String cssSelector)
ElementsCollection(Driver driver, java.util.Collection<? extends org.openqa.selenium.WebElement> elements)
ElementsCollection(Driver driver, org.openqa.selenium.By seleniumSelector)
ElementsCollection(Driver driver, org.openqa.selenium.WebElement parent, java.lang.String cssSelector)
ElementsCollection(Driver driver, org.openqa.selenium.WebElement parent, org.openqa.selenium.By seleniumSelector)
ElementsCollection(WebElementsCollection collection)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static java.lang.String
elementsToString(Driver driver, java.util.Collection<org.openqa.selenium.WebElement> elements)
Outputs string presentation of the element's collectionElementsCollection
exclude(Condition condition)
Filters elements excluding those which met the given condition (lazy evaluation) ATTENTION! Doesn't start any search yet.ElementsCollection
excludeWith(Condition condition)
Filters elements excluding those which met the given condition (lazy evaluation) ATTENTION! Doesn't start any search yet.ElementsCollection
filter(Condition condition)
Filters collection elements based on the given condition (lazy evaluation) ATTENTION! Doesn't start any search yet.ElementsCollection
filterBy(Condition condition)
Filters collection elements based on the given condition (lazy evaluation) ATTENTION! Doesn't start any search yet.SelenideElement
find(Condition condition)
Find the first element which met the given condition (lazy evaluation) ATTENTION! Doesn't start any search yet.SelenideElement
findBy(Condition condition)
Find the first element which met the given condition (lazy evaluation) ATTENTION! Doesn't start any search yet.SelenideElement
first()
returns the first element of the collection ATTENTION! Doesn't start any search yet.ElementsCollection
first(int elements)
returns the first n elements of the collection (lazy evaluation) ATTENTION! Doesn't start any search yet.SelenideElement
get(int index)
Gets the n-th element of collection (lazy evaluation) ATTENTION! Doesn't start any search yet.java.util.Iterator<SelenideElement>
iterator()
SelenideElement
last()
returns the last element of the collection (lazy evaluation) ATTENTION! Doesn't start any search yet.ElementsCollection
last(int elements)
returns the last n elements of the collection (lazy evaluation) ATTENTION! Doesn't start any search yet.java.util.ListIterator<SelenideElement>
listIterator(int index)
protected ElementsCollection
should(java.lang.String prefix, long timeoutMs, CollectionCondition... conditions)
ElementsCollection
shouldBe(CollectionCondition... conditions)
For example:$$(".error").shouldBe(empty)
ElementsCollection
shouldBe(CollectionCondition condition, long timeoutMs)
ElementsCollection
shouldHave(CollectionCondition... conditions)
For example:$$(".error").shouldHave(size(3))
$$(".error").shouldHave(texts("Error1", "Error2"))
ElementsCollection
shouldHave(CollectionCondition condition, long timeoutMs)
Check if a collection matches given condition within given periodElementsCollection
shouldHaveSize(int expectedSize)
Deprecated.int
size()
return actual size of the collection, doesn't wait on collection to be loaded.ElementsCollection
snapshot()
Takes the snapshot of current state of this collection.java.util.List<java.lang.String>
texts()
Gets all the texts in elements collectionstatic java.util.List<java.lang.String>
texts(java.util.Collection<org.openqa.selenium.WebElement> elements)
Fail-safe method for retrieving texts of given elements.java.lang.Object[]
toArray()
java.lang.String
toString()
protected void
waitUntil(CollectionCondition condition, long timeoutMs)
-
Methods inherited from class java.util.AbstractList
add, add, addAll, clear, equals, hashCode, indexOf, lastIndexOf, listIterator, remove, removeRange, set, subList
-
Methods inherited from class java.util.AbstractCollection
addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray
-
-
-
-
Constructor Detail
-
ElementsCollection
public ElementsCollection(WebElementsCollection collection)
-
ElementsCollection
public ElementsCollection(Driver driver, java.util.Collection<? extends org.openqa.selenium.WebElement> elements)
-
ElementsCollection
public ElementsCollection(Driver driver, java.lang.String cssSelector)
-
ElementsCollection
public ElementsCollection(Driver driver, org.openqa.selenium.By seleniumSelector)
-
ElementsCollection
public ElementsCollection(Driver driver, org.openqa.selenium.WebElement parent, java.lang.String cssSelector)
-
ElementsCollection
public ElementsCollection(Driver driver, org.openqa.selenium.WebElement parent, org.openqa.selenium.By seleniumSelector)
-
-
Method Detail
-
shouldHaveSize
@Nonnull public ElementsCollection shouldHaveSize(int expectedSize)
Deprecated. Use$$.shouldHave(size(expectedSize))
instead.
-
shouldBe
@Nonnull public ElementsCollection shouldBe(CollectionCondition... conditions)
For example:$$(".error").shouldBe(empty)
-
shouldBe
@Nonnull public ElementsCollection shouldBe(CollectionCondition condition, long timeoutMs)
-
shouldHave
@Nonnull public ElementsCollection shouldHave(CollectionCondition... conditions)
For example:$$(".error").shouldHave(size(3))
$$(".error").shouldHave(texts("Error1", "Error2"))
-
shouldHave
@Nonnull public ElementsCollection shouldHave(CollectionCondition condition, long timeoutMs)
Check if a collection matches given condition within given period- Parameters:
timeoutMs
- maximum waiting time in milliseconds
-
should
protected ElementsCollection should(java.lang.String prefix, long timeoutMs, CollectionCondition... conditions)
-
waitUntil
protected void waitUntil(CollectionCondition condition, long timeoutMs)
-
filter
@Nonnull public ElementsCollection filter(Condition condition)
Filters collection elements based on the given condition (lazy evaluation) ATTENTION! Doesn't start any search yet. Search will be started when action or assert is applied- Parameters:
condition
- condition- Returns:
- ElementsCollection
-
filterBy
@Nonnull public ElementsCollection filterBy(Condition condition)
Filters collection elements based on the given condition (lazy evaluation) ATTENTION! Doesn't start any search yet. Search will be started when action or assert is applied- Parameters:
condition
- condition- Returns:
- ElementsCollection
- See Also:
filter(Condition)
-
exclude
@Nonnull public ElementsCollection exclude(Condition condition)
Filters elements excluding those which met the given condition (lazy evaluation) ATTENTION! Doesn't start any search yet. Search will be started when action or assert is applied- Parameters:
condition
- condition- Returns:
- ElementsCollection
-
excludeWith
@Nonnull public ElementsCollection excludeWith(Condition condition)
Filters elements excluding those which met the given condition (lazy evaluation) ATTENTION! Doesn't start any search yet. Search will be started when action or assert is applied- Parameters:
condition
- condition- Returns:
- ElementsCollection
- See Also:
exclude(Condition)
-
find
@Nonnull public SelenideElement find(Condition condition)
Find the first element which met the given condition (lazy evaluation) ATTENTION! Doesn't start any search yet. Search will be started when action or assert is applied- Parameters:
condition
- condition- Returns:
- SelenideElement
-
findBy
@Nonnull public SelenideElement findBy(Condition condition)
Find the first element which met the given condition (lazy evaluation) ATTENTION! Doesn't start any search yet. Search will be started when action or assert is applied- Parameters:
condition
- condition- Returns:
- SelenideElement
- See Also:
find(Condition)
-
texts
@Nonnull public java.util.List<java.lang.String> texts()
Gets all the texts in elements collection- Returns:
- array of texts
-
texts
@Nonnull public static java.util.List<java.lang.String> texts(java.util.Collection<org.openqa.selenium.WebElement> elements)
Fail-safe method for retrieving texts of given elements.- Parameters:
elements
- Any collection of WebElements- Returns:
- Array of texts (or exceptions in case of any WebDriverExceptions)
-
elementsToString
@Nonnull public static java.lang.String elementsToString(Driver driver, @Nullable java.util.Collection<org.openqa.selenium.WebElement> elements)
Outputs string presentation of the element's collection- Parameters:
elements
- elements of string- Returns:
- String
-
get
public SelenideElement get(int index)
Gets the n-th element of collection (lazy evaluation) ATTENTION! Doesn't start any search yet. Search will be started when action or assert is applied (.click(), should..() etc.)- Specified by:
get
in interfacejava.util.List<SelenideElement>
- Specified by:
get
in classjava.util.AbstractList<SelenideElement>
- Parameters:
index
- 0..N- Returns:
- the n-th element of collection
-
first
@Nonnull public SelenideElement first()
returns the first element of the collection ATTENTION! Doesn't start any search yet. Search will be started when action or assert is applied (.click(), should..() etc.) NOTICE: $(css) is faster and returns the same result as $$(css).first()- Returns:
- the first element of the collection
-
last
@Nonnull public SelenideElement last()
returns the last element of the collection (lazy evaluation) ATTENTION! Doesn't start any search yet. Search will be started when action or assert is applied (.click(), should..() etc.)- Returns:
- the last element of the collection
-
first
@Nonnull public ElementsCollection first(int elements)
returns the first n elements of the collection (lazy evaluation) ATTENTION! Doesn't start any search yet. Search will be started when action or assert is applied (.click(), should..() etc.)- Parameters:
elements
- number of elements 1..N
-
last
@Nonnull public ElementsCollection last(int elements)
returns the last n elements of the collection (lazy evaluation) ATTENTION! Doesn't start any search yet. Search will be started when action or assert is applied (.click(), should..() etc.)- Parameters:
elements
- number of elements 1..N
-
size
public int size()
return actual size of the collection, doesn't wait on collection to be loaded. ATTENTION not recommended for use in tests. Use collection.shouldHave(size(n)); for assertions instead.- Specified by:
size
in interfacejava.util.Collection<SelenideElement>
- Specified by:
size
in interfacejava.util.List<SelenideElement>
- Specified by:
size
in classjava.util.AbstractCollection<SelenideElement>
- Returns:
- actual size of the collection
-
iterator
@Nonnull public java.util.Iterator<SelenideElement> iterator()
- Specified by:
iterator
in interfacejava.util.Collection<SelenideElement>
- Specified by:
iterator
in interfacejava.lang.Iterable<SelenideElement>
- Specified by:
iterator
in interfacejava.util.List<SelenideElement>
- Overrides:
iterator
in classjava.util.AbstractList<SelenideElement>
-
listIterator
@Nonnull public java.util.ListIterator<SelenideElement> listIterator(int index)
- Specified by:
listIterator
in interfacejava.util.List<SelenideElement>
- Overrides:
listIterator
in classjava.util.AbstractList<SelenideElement>
-
toArray
@Nonnull public java.lang.Object[] toArray()
- Specified by:
toArray
in interfacejava.util.Collection<SelenideElement>
- Specified by:
toArray
in interfacejava.util.List<SelenideElement>
- Overrides:
toArray
in classjava.util.AbstractCollection<SelenideElement>
-
snapshot
@Nonnull public ElementsCollection 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
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.util.AbstractCollection<SelenideElement>
-
-