T - the type of the AbstractElement subclass representing a Vaadin
componentpublic class ElementQuery<T extends AbstractElement> extends Object
The typical end-user use case for a ElementQuery is as follows - in this
example, we're looking for the fifth Vaadin Button from inside a
TestBenchTestCase:
ButtonElement e = $(ButtonElement.class).index(4).first(); ButtonElement e = $(ButtonElement.class).all().get(4);
Second alternative results in slightly more network traffic. These two are
not identical when you use search hierarchy. See the documentation for
index(int).
For a more advanced example, we'll find the second Label inside a VerticalLayout inside a GridLayout:
LabelElement e = $(LabelElement.class).index(1).in(VerticalLayoutElement.class)
.in(GridLayoutElement.class).first();
To find your own component, extend AbstractElement class and use ServerClass annotation to define it's full class name e.g. com.vaadin.example.MyWidget
| Constructor and Description |
|---|
ElementQuery(Class<T> elementClass)
Instantiate a new ElementQuery for given type.
|
| Modifier and Type | Method and Description |
|---|---|
<E extends AbstractElement> |
$(Class<E> cls)
Prepare a
ElementQuery instance to use for locating components on
the client. |
<E extends AbstractElement> |
$$(Class<E> cls)
Prepare a
ElementQuery instance to use for locating components on
the client. |
List<T> |
all()
Search the open Vaadin application for a list of matching components
relative to given context.
|
ElementQuery<T> |
caption(String caption)
Add a requirement to only accept components with a specified caption
value.
|
<E extends AbstractElement> |
child(ElementQuery<E> query)
Adds another query to the search hierarchy of this ElementQuery.
|
ElementQuery<T> |
context(org.openqa.selenium.SearchContext searchContext)
Specify a different
SearchContext to use. |
boolean |
exists()
Checks if this ElementQuery describes existing elements.
|
T |
first()
Search the open Vaadin application for a matching component relative to
given context.
|
protected String |
generateQuery()
Generates a vaadin locator path.
|
T |
get(int index)
Search the open Vaadin application for a matching component relative to
given context.
|
protected org.openqa.selenium.SearchContext |
getContext()
Return the
SearchContext previously set with the in(com.vaadin.testbench.ElementQuery<E>)
call. |
T |
id(String id)
Executes a search for element with given ID.
|
<E extends AbstractElement> |
in(ElementQuery<E> query)
Adds another query to the search hierarchy of this ElementQuery.
|
ElementQuery<T> |
index(int index)
Set an index requirement for the current ElementQuery.
|
T |
last()
Search the open Vaadin application for a matching component relative to
given context.
|
ElementQuery<T> |
recursive(boolean recursion)
For advanced use.
|
ElementQuery<T> |
state(String varname,
String value)
For advanced use.
|
public ElementQuery<T> recursive(boolean recursion)
recursion - Boolean value. false for direct child searchpublic <E extends AbstractElement> ElementQuery<E> $(Class<E> cls)
ElementQuery instance to use for locating components on
the client. The returned object can be manipulated to uniquely identify
the sought-after object. If this function gets called through an element,
it uses the element as its search context. Otherwise the search context
is the driver.E - the type of the element classcls - AbstractElement subclassElementQuery instancepublic <E extends AbstractElement> ElementQuery<E> $$(Class<E> cls)
ElementQuery instance to use for locating components on
the client. The returned object can be manipulated to uniquely identify
the sought-after object. If this function gets called through an element,
it uses the element as its search context. Otherwise the search context
is the driver.
This search is not recursive and can find the given hierarchy only if it
can be found as direct children of given context. The same can be done
with $(Foo.class).recursive(false) E - the type of the element classcls - AbstractElement subclassElementQuery instancepublic <E extends AbstractElement> ElementQuery<T> in(ElementQuery<E> query)
E - the type of the element classquery - ElementQuery instance to be used as part of search hierarchy.public <E extends AbstractElement> ElementQuery<T> child(ElementQuery<E> query)
E - the type of the element classquery - ElementQuery instance to be used as part of search hierarchy.public T id(String id)
id - a String valuepublic ElementQuery<T> caption(String caption)
caption - a String valuepublic ElementQuery<T> state(String varname, String value)
varname - name of the desired Vaadin object state variablevalue - the state variable value as a Stringpublic ElementQuery<T> index(int index)
.in() or .childOf() the index
requirement is set for the latest referenced Element type. For example
the .index() call in $(Foo.class).index(4) would apply to
the Foo type (referring to the fifth instance of Foo that
can be found in the current search context) in the hierarchy, while in
$(Foo.class).in(Bar.class).index(3) it would apply to the Bar
type, and the search would refer to all Foo instances
found in every Bar instance which is the fourth Bar
instance within the search context and any and all sub-contexts.
When searching for one Element without search hierarchy this is
equivalent to .all().get(index).
Note the difference between .in() and .childOf():
$(LabelElement.class).index(1).in(HorizontalLayoutElement.class)
does a depth first search in all HorizontalLayout instances and
returns the second Label instance from each result.
$(LabelElement.class).index(1).childOf(HorizontalLayoutElement.class)
only finds Labels the second direct children of all
HorizontalLayout instances.
index - zero-based index of the desired elementpublic ElementQuery<T> context(org.openqa.selenium.SearchContext searchContext)
SearchContext to use.searchContext - a SearchContext; usually a TestBenchElement
instance.protected org.openqa.selenium.SearchContext getContext()
SearchContext previously set with the in(com.vaadin.testbench.ElementQuery<E>)
call.public T first()
public T last()
public T get(int index)
index - Post filtering indexpublic boolean exists()
public List<T> all()
protected String generateQuery()
Copyright © 2012-2025 Vaadin Ltd. All Rights Reserved.