com.vaadin.testbench.
Class ElementQuery<T extends TestBenchElement>
Query class used for finding a given element inside a given search context.
The search context is either a WebDriver
instance which searches
starting from the root of the current document, or a WebElement
instance, which searches both in the light DOM and inside the shadow root of
the given element.
When the search context is a WebElement
, the shadow root is searched
first. E.g. when searching by ID and the same ID is used by a light DOM child
of the element and also inside its shadow root, the element from the shadow
root is returned.
The element class specified in the constructor defines the tag name which is searched for an also the type of element returned.
-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionElementQuery
(Class<T> elementClass) Instantiate a new ElementQuery to look for the given type of element.
ElementQuery
(Class<T> elementClass, String tagName) Instantiate a new ElementQuery to look for the given type of element.
-
Method Summary
Modifier and TypeMethodDescriptionall()
Search the open Vaadin application for a list of matching components relative to given context.
Requires the given attribute to match the given value.
attributeContains
(String name, String token) Requires the given attribute to contain the given value.
context
(org.openqa.selenium.SearchContext searchContext) Sets the context to search inside.
boolean
exists()
Checks if this ElementQuery describes existing elements.
first()
Executes the search and returns the first result.
get
(int index) Executes the search and returns the requested element.
protected org.openqa.selenium.SearchContext
Returns the context (element or driver) to search inside.
hasAttribute
(String name) Requires the given attribute to be set.
Executes a search for element with the given id.
last()
Executes the search and returns the last result.
onPage()
Defines that the query should start the search from the root of the page, in practice from the
<body>
tag.Executes the search and returns the first result once at least once result is available.
waitForFirst
(long timeOutInSeconds) Executes the search and returns the first result once at least once result is available.
-
Constructor Details
-
ElementQuery
Instantiate a new ElementQuery to look for the given type of element.
Parameters:
elementClass
- the type of element to look for and return -
ElementQuery
Instantiate a new ElementQuery to look for the given type of element.
Parameters:
elementClass
- the type of element to returntagName
- the tag name of the element to find
-
-
Method Details
-
id
Executes a search for element with the given id.
Parameters:
id
- the id to look upReturns:
the element with the given id
Throws:
org.openqa.selenium.NoSuchElementException
- if no element is found -
hasAttribute
Requires the given attribute to be set.
Parameters:
name
- the attribute nameReturns:
this element query instance for chaining
-
attribute
Requires the given attribute to match the given value.
For matching a token in the attribute, see
attributeContains(String, String)
.Parameters:
name
- the attribute namevalue
- the attribute valueReturns:
this element query instance for chaining
-
attributeContains
Requires the given attribute to contain the given value.
Compares with space separated tokens so that e.g.
attributeContains('class','myclass');
matchesclass='someclass myclass'
.For matching the full attribute value, see
attribute(String, String)
.Parameters:
name
- the attribute nametoken
- the token to look forReturns:
this element query instance for chaining
-
context
Sets the context to search inside.
Parameters:
searchContext
- aSearchContext
; either aTestBenchElement
orWebDriver
(to search from the root) instanceReturns:
this element query instance for chaining
-
onPage
Defines that the query should start the search from the root of the page, in practice from the
<body>
tag.Returns:
this element query instance for chaining
-
getContext
protected org.openqa.selenium.SearchContext getContext()Returns the context (element or driver) to search inside.
Returns:
a
SearchContext
instance -
first
Executes the search and returns the first result.
Returns:
The element of the type specified in the constructor
Throws:
org.openqa.selenium.NoSuchElementException
- if no element is found -
waitForFirst
Executes the search and returns the first result once at least once result is available.
This method is identical to
first()
if at least one element is present. If no element is found, this method will keep searching until an element is found or if 10 seconds has elapsed.Returns:
The element of the type specified in the constructor
-
waitForFirst
Executes the search and returns the first result once at least once result is available.
This method is identical to
first()
if at least one element is present. If no element is found, this method will keep searching until an element is found ortimeOutInSeconds
seconds has elapsed.Parameters:
timeOutInSeconds
- timeout in seconds before this method throws aNoSuchElementException
exceptionReturns:
The element of the type specified in the constructor
-
last
Executes the search and returns the last result.
Returns:
The element of the type specified in the constructor
Throws:
org.openqa.selenium.NoSuchElementException
- if no element is found -
get
Executes the search and returns the requested element.
Parameters:
index
- the index of the element to returnReturns:
The element of the type specified in the constructor
Throws:
org.openqa.selenium.NoSuchElementException
- if no element is found -
exists
public boolean exists()Checks if this ElementQuery describes existing elements. Same as .all().isEmpty().
Returns:
true if elements exists. false if not
-
all
Search the open Vaadin application for a list of matching components relative to given context.
Returns:
Components as a list of corresponding elements
-