public class ElementQuery<T extends TestBenchElement> extends Object
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.
Modifier and Type | Class and Description |
---|---|
static class |
ElementQuery.AttributeMatch |
Constructor and Description |
---|
ElementQuery(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.
|
Modifier and Type | Method and Description |
---|---|
List<T> |
all()
Search the open Vaadin application for a list of matching components
relative to given context.
|
ElementQuery<T> |
attribute(String name,
String value)
Requires the given attribute to match the given value.
|
ElementQuery<T> |
attributeContains(String name,
String token)
Requires the given attribute to contain the given value.
|
ElementQuery<T> |
context(org.openqa.selenium.SearchContext searchContext)
Sets the context to search inside.
|
boolean |
exists()
Checks if this ElementQuery describes existing elements.
|
T |
first()
Executes the search and returns the first result.
|
T |
get(int index)
Executes the search and returns the requested element.
|
protected org.openqa.selenium.SearchContext |
getContext()
Return the context (element or driver) to search inside.
|
T |
id(String id)
Executes a search for element with the given id.
|
T |
last()
Executes the search and returns the last result.
|
ElementQuery<T> |
onPage()
Defines that the query should start the search from the root of the page,
in practice from the
<body> tag. |
T |
waitForFirst()
Executes the search and returns the first result once at least once
result is available.
|
public ElementQuery(Class<T> elementClass)
elementClass
- the type of element to look for and returnpublic T id(String id)
id
- the id to look uporg.openqa.selenium.NoSuchElementException
- if no element is foundpublic ElementQuery<T> attribute(String name, String value)
For matching a token in the attribute, see
attributeContains(String, String)
.
name
- the attribute namevalue
- the attribute valuepublic ElementQuery<T> attributeContains(String name, String token)
Compares with space separated tokens so that e.g.
attributeContains('class','myclass');
matches
class='someclass myclass'
.
For matching the full attribute value, see
attribute(String, String)
.
name
- the attribute nametoken
- the token to look forpublic ElementQuery<T> context(org.openqa.selenium.SearchContext searchContext)
searchContext
- a SearchContext
; either a TestBenchElement
or
WebDriver
(to search from the root) instancepublic ElementQuery<T> onPage()
<body>
tag.protected org.openqa.selenium.SearchContext getContext()
public T first()
org.openqa.selenium.NoSuchElementException
- if no element is foundpublic T waitForFirst()
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.
org.openqa.selenium.TimeoutException
- if no element is found after 10 seconds has elapsedpublic T last()
org.openqa.selenium.NoSuchElementException
- if no element is foundpublic T get(int index)
org.openqa.selenium.NoSuchElementException
- if no element is foundpublic boolean exists()
Copyright © 2018. All rights reserved.