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(CollectionSource collection)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description ElementsCollectionas(java.lang.String alias)Give this collection a human-readable name Caution: you probably don't need this method.static java.lang.StringelementsToString(Driver driver, java.util.Collection<org.openqa.selenium.WebElement> elements)Outputs string presentation of the element's collectionElementsCollectionexclude(Condition condition)Filters elements excluding those which met the given condition (lazy evaluation)ElementsCollectionexcludeWith(Condition condition)Filters elements excluding those which met the given condition (lazy evaluation)ElementsCollectionfilter(Condition condition)Filters collection elements based on the given condition (lazy evaluation)ElementsCollectionfilterBy(Condition condition)Filters collection elements based on the given condition (lazy evaluation)SelenideElementfind(Condition condition)Find the first element which met the given condition (lazy evaluation)SelenideElementfindBy(Condition condition)Find the first element which met the given condition (lazy evaluation)SelenideElementfirst()returns the first element of the collection (lazy evaluation)ElementsCollectionfirst(int elements)returns the first n elements of the collection (lazy evaluation)SelenideElementget(int index)Gets the n-th element of collection (lazy evaluation)java.util.Iterator<SelenideElement>iterator()Does not reload collection elements while iterating it.SelenideElementlast()returns the last element of the collection (lazy evaluation)ElementsCollectionlast(int elements)returns the last n elements of the collection (lazy evaluation)java.util.ListIterator<SelenideElement>listIterator(int index)Does not reload collection elements while iterating it.ElementsCollectionshould(CollectionCondition... conditions)Check if a collection matches given condition(s).ElementsCollectionshould(CollectionCondition condition, java.time.Duration timeout)Check if a collection matches a given condition within the given time period.protected ElementsCollectionshould(java.lang.String prefix, java.time.Duration timeout, CollectionCondition... conditions)ElementsCollectionshouldBe(CollectionCondition... conditions)For example:$$(".error").shouldBe(empty)ElementsCollectionshouldBe(CollectionCondition condition, long timeoutMs)Deprecated.ElementsCollectionshouldBe(CollectionCondition condition, java.time.Duration timeout)ElementsCollectionshouldHave(CollectionCondition... conditions)For example:$$(".error").shouldHave(size(3))$$(".error").shouldHave(texts("Error1", "Error2"))ElementsCollectionshouldHave(CollectionCondition condition, long timeoutMs)Deprecated.ElementsCollectionshouldHave(CollectionCondition condition, java.time.Duration timeout)Check if a collection matches given condition within given periodElementsCollectionshouldHaveSize(int expectedSize)Deprecated.Use$$.shouldHave(size(expectedSize))instead.intsize()return actual size of the collection, doesn't wait on collection to be loaded.ElementsCollectionsnapshot()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.StringtoString()protected voidwaitUntil(CollectionCondition condition, java.time.Duration timeout)-
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(CollectionSource 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)
-
-
Method Detail
-
shouldHaveSize
@Nonnull @Deprecated public ElementsCollection shouldHaveSize(int expectedSize)
Deprecated.Use$$.shouldHave(size(expectedSize))instead.
-
should
@Nonnull public ElementsCollection should(CollectionCondition... conditions)
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
@Nonnull public ElementsCollection should(CollectionCondition condition, java.time.Duration timeout)
Check if a collection matches a given condition within the given time period.- Parameters:
timeout- maximum waiting time
-
shouldBe
@Nonnull public ElementsCollection shouldBe(CollectionCondition... conditions)
For example:$$(".error").shouldBe(empty)
-
shouldBe
@Nonnull public ElementsCollection shouldBe(CollectionCondition condition, java.time.Duration timeout)
-
shouldBe
@Nonnull @Deprecated public ElementsCollection shouldBe(CollectionCondition condition, long timeoutMs)
Deprecated.
-
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, java.time.Duration timeout)
Check if a collection matches given condition within given period- Parameters:
timeout- maximum waiting time
-
shouldHave
@Nonnull @Deprecated public ElementsCollection shouldHave(CollectionCondition condition, long timeoutMs)
Deprecated.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, java.time.Duration timeout, CollectionCondition... conditions)
-
waitUntil
protected void waitUntil(CollectionCondition condition, java.time.Duration timeout)
-
filter
@CheckReturnValue @Nonnull public ElementsCollection filter(Condition condition)
Filters collection elements based on the given condition (lazy evaluation)- Parameters:
condition- condition- Returns:
- ElementsCollection
- See Also:
- Lazy loading
-
filterBy
@CheckReturnValue @Nonnull public ElementsCollection filterBy(Condition condition)
Filters collection elements based on the given condition (lazy evaluation)- Parameters:
condition- condition- Returns:
- ElementsCollection
- See Also:
filter(Condition), Lazy loading
-
exclude
@CheckReturnValue @Nonnull public ElementsCollection exclude(Condition condition)
Filters elements excluding those which met the given condition (lazy evaluation)- Parameters:
condition- condition- Returns:
- ElementsCollection
- See Also:
- Lazy loading
-
excludeWith
@CheckReturnValue @Nonnull public ElementsCollection excludeWith(Condition condition)
Filters elements excluding those which met the given condition (lazy evaluation)- Parameters:
condition- condition- Returns:
- ElementsCollection
- See Also:
exclude(Condition), Lazy loading
-
find
@CheckReturnValue @Nonnull public SelenideElement find(Condition condition)
Find the first element which met the given condition (lazy evaluation)- Parameters:
condition- condition- Returns:
- SelenideElement
- See Also:
- Lazy loading
-
findBy
@CheckReturnValue @Nonnull public SelenideElement findBy(Condition condition)
Find the first element which met the given condition (lazy evaluation)- Parameters:
condition- condition- Returns:
- SelenideElement
- See Also:
find(Condition), Lazy loading
-
texts
@CheckReturnValue @Nonnull public java.util.List<java.lang.String> texts()
Gets all the texts in elements collection- Returns:
- array of texts
- See Also:
- NOT RECOMMENDED
-
texts
@CheckReturnValue @Nonnull public static java.util.List<java.lang.String> texts(@Nullable 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
@CheckReturnValue @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:
- e.g. "[
foo
,bar
]" - See Also:
- NOT RECOMMENDED
-
get
@CheckReturnValue @Nonnull public SelenideElement get(int index)
Gets the n-th element of collection (lazy evaluation)- Specified by:
getin interfacejava.util.List<SelenideElement>- Specified by:
getin classjava.util.AbstractList<SelenideElement>- Parameters:
index- 0..N- Returns:
- the n-th element of collection
- See Also:
- Lazy loading
-
first
@CheckReturnValue @Nonnull public SelenideElement 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:
- Lazy loading
-
last
@CheckReturnValue @Nonnull public SelenideElement last()
returns the last element of the collection (lazy evaluation)- Returns:
- the last element of the collection
- See Also:
- Lazy loading
-
first
@CheckReturnValue @Nonnull public ElementsCollection first(int elements)
returns the first n elements of the collection (lazy evaluation)- Parameters:
elements- number of elements 1..N- See Also:
- Lazy loading
-
last
@CheckReturnValue @Nonnull public ElementsCollection last(int elements)
returns the last n elements of the collection (lazy evaluation)- Parameters:
elements- number of elements 1..N- See Also:
- Lazy loading
-
size
@CheckReturnValue public int size()
return actual size of the collection, doesn't wait on collection to be loaded.
- Specified by:
sizein interfacejava.util.Collection<SelenideElement>- Specified by:
sizein interfacejava.util.List<SelenideElement>- Specified by:
sizein classjava.util.AbstractCollection<SelenideElement>- Returns:
- actual size of the collection
- See Also:
- NOT RECOMMENDED
-
iterator
@CheckReturnValue @Nonnull public java.util.Iterator<SelenideElement> iterator()
Does not reload collection elements while iterating it. Not recommended to use.- Specified by:
iteratorin interfacejava.util.Collection<SelenideElement>- Specified by:
iteratorin interfacejava.lang.Iterable<SelenideElement>- Specified by:
iteratorin interfacejava.util.List<SelenideElement>- Overrides:
iteratorin classjava.util.AbstractList<SelenideElement>- See Also:
- NOT RECOMMENDED
-
listIterator
@CheckReturnValue @Nonnull public java.util.ListIterator<SelenideElement> listIterator(int index)
Does not reload collection elements while iterating it. Not recommended to use.- Specified by:
listIteratorin interfacejava.util.List<SelenideElement>- Overrides:
listIteratorin classjava.util.AbstractList<SelenideElement>- See Also:
- NOT RECOMMENDED
-
toArray
@CheckReturnValue @Nonnull public java.lang.Object[] toArray()
- Specified by:
toArrayin interfacejava.util.Collection<SelenideElement>- Specified by:
toArrayin interfacejava.util.List<SelenideElement>- Overrides:
toArrayin classjava.util.AbstractCollection<SelenideElement>- See Also:
- NOT RECOMMENDED
-
snapshot
@CheckReturnValue @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
-
as
@CheckReturnValue @Nonnull public ElementsCollection as(java.lang.String alias)
Give this collection a human-readable name Caution: 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
@CheckReturnValue public java.lang.String toString()
- Overrides:
toStringin classjava.util.AbstractCollection<SelenideElement>
-
-