public class QueryFactory
extends java.lang.Object
import static com.abmash.api.query.QueryFactory.*;
Constructor and Description |
---|
QueryFactory() |
Modifier and Type | Method and Description |
---|---|
static Predicate |
above(HtmlElement element)
Finds elements visually above the given
HtmlElement . |
static Predicate |
above(HtmlElements elements)
Finds elements visually above the given
HtmlElements . |
static Predicate |
above(Predicate... predicates)
Finds elements visually above the elements that match the given predicates.
|
static Predicate |
aboveAll(HtmlElement element)
Finds elements visually above all the elements that match the given
HtmlElement . |
static Predicate |
aboveAll(HtmlElements elements)
Finds elements visually above all the elements that match the given
HtmlElements . |
static Predicate |
aboveAll(Predicate... predicates)
Finds elements visually above all the elements that match the given predicates.
|
static Predicate |
and(Predicate... predicates)
Defines a boolean "and" predicate.
|
static Predicate |
below(HtmlElement element)
Finds elements visually below the given
HtmlElement . |
static Predicate |
below(HtmlElements elements)
Finds elements visually below the given
HtmlElements . |
static Predicate |
below(Predicate... predicates)
Finds elements visually above the elements that match the given predicates.
|
static Predicate |
belowAll(HtmlElement element)
Finds elements visually below all the elements that match the given
HtmlElement . |
static Predicate |
belowAll(HtmlElements elements)
Finds elements visually below all the elements that match the given
HtmlElements . |
static Predicate |
belowAll(Predicate... predicates)
Finds elements visually below all the elements that match the given predicates.
|
static Predicate |
checkable()
Finds all input elements that can be used to check/uncheck an option.
|
static Predicate |
checkable(java.lang.String text)
Finds input elements that can be used to check/uncheck an option and are labeled with a specific text.
|
static Predicate |
choosable()
Finds all input elements that can be used to choose from multiple options.
|
static Predicate |
choosable(java.lang.String text)
Finds input elements that can be used to choose from multiple options and are labeled with a specific text.
|
static Predicate |
clickable()
Finds all clickable elements.
|
static Predicate |
clickable(java.lang.String text)
Finds clickable elements that contain a specific text.
|
static Predicate |
closeTo(DirectionOptions options,
HtmlElement element)
Finds elements visually close to the given
HtmlElement . |
static Predicate |
closeTo(DirectionOptions options,
HtmlElements elements)
Finds elements visually close to the given
HtmlElements . |
static Predicate |
closeTo(DirectionOptions options,
Predicate... predicates)
Finds elements visually close to the elements that match the given predicates.
|
static Predicate |
closeTo(HtmlElement element)
Finds elements visually close to the given
HtmlElement , with a maximum distance of 300 pixels. |
static Predicate |
closeTo(HtmlElements elements)
Finds elements visually close to the given
HtmlElements , with a maximum distance of 300 pixels. |
static Predicate |
closeTo(int maxDistance,
HtmlElement element)
Finds elements visually close to the given
HtmlElement , with a maximum distance. |
static Predicate |
closeTo(int maxDistance,
HtmlElements elements)
Finds elements visually close to the given
HtmlElements , with a maximum distance. |
static Predicate |
closeTo(int maxDistance,
Predicate... predicates)
Finds elements visually close to the elements that match the given predicates, with a maximum distance.
|
static Predicate |
closeTo(Predicate... predicates)
Finds elements visually close to the elements that match the given predicates, with a maximum distance of 300 pixels.
|
static Predicate |
color(java.awt.Color color)
Finds elements that match the desired color.
|
static Predicate |
color(java.awt.Color color,
double tolerance,
double dominance)
Finds elements that match the desired color.
|
static Predicate |
color(ColorName colorName)
Finds elements that match the desired color.
|
static Predicate |
color(ColorName colorName,
double tolerance,
double dominance)
Finds elements that match the desired color.
|
static Predicate |
color(ColorName colorName,
Tolerance tolerance,
Dominance dominance)
Finds elements that match the desired color.
|
static Predicate |
color(java.awt.Color color,
Tolerance tolerance,
Dominance dominance)
Finds elements that match the desired color.
|
static Predicate |
contains(java.lang.String text)
Finds elements that contain a specific text or attribute value.
|
static Predicate |
datepicker()
Finds input elements that can be used to select a date.
|
static Predicate |
datepicker(java.lang.String text)
Finds input elements that can be used to select a date and are labeled with a specific text.
|
static Predicate |
elements(HtmlElements elements)
Returns the given
HtmlElements as predicate result. |
static Predicate |
frame(java.lang.String text)
Finds frames and iframe elements that are labeled/captioned with a specific text.
|
static Predicate |
headline()
Finds all elements that are titles/headlines or have a bigger font size than average elements.
|
static Predicate |
headline(java.lang.String text)
Finds title/headline elements that contain a specific text and have a bigger font size than average elements.
|
static Predicate |
image()
Finds all image elements.
|
static Predicate |
image(java.lang.String text)
Finds image elements that are labeled/captioned with a specific text.
|
static Predicate |
leftOf(HtmlElement element)
Finds elements visually left of the given
HtmlElement . |
static Predicate |
leftOf(HtmlElements elements)
Finds elements visually left of the given
HtmlElements . |
static Predicate |
leftOf(Predicate... predicates)
Finds elements visually left of the elements that match the given predicates.
|
static Predicate |
leftOfAll(HtmlElement element)
Finds elements visually left of all the elements that match the given
HtmlElement . |
static Predicate |
leftOfAll(HtmlElements elements)
Finds elements visually left of all the elements that match the given
HtmlElements . |
static Predicate |
leftOfAll(Predicate... predicates)
Finds elements visually left of all the elements that match the given predicates.
|
static Predicate |
link()
Finds all link elements.
|
static Predicate |
link(java.lang.String text)
Finds link elements that contain a specific text.
|
static Predicate |
not(Predicate... predicates)
Defines a boolean "not" predicate.
|
static Predicate |
or(Predicate... predicates)
Defines a boolean "or" predicate.
|
static Query |
query(Browser browser,
Predicate... predicates)
Creates a new query to find elements in the specified browser and with the given predicates, used by calling
Browser.query(Predicate...) . |
static Predicate |
rightOf(HtmlElement element)
Finds elements visually right of the given
HtmlElement . |
static Predicate |
rightOf(HtmlElements elements)
Finds elements visually right of the given
HtmlElements . |
static Predicate |
rightOf(Predicate... predicates)
Finds elements visually right of the elements that match the given predicates.
|
static Predicate |
rightOfAll(HtmlElement element)
Finds elements visually right of all the elements that match the given
HtmlElement . |
static Predicate |
rightOfAll(HtmlElements elements)
Finds elements visually right of all the elements that match the given
HtmlElements . |
static Predicate |
rightOfAll(Predicate... predicates)
Finds elements visually right of all the elements that match the given predicates.
|
static Predicate |
select(java.lang.String selector)
Finds elements that match the given selector (CSS or jQuery).
|
static Predicate |
submittable()
Finds input elements that can be used to submit a form.
|
static Predicate |
submittable(java.lang.String text)
Finds input elements that can be used to submit a form and are labeled with a specific text.
|
static Predicate |
text()
Finds all elements that contain text.
|
static Predicate |
text(java.lang.String text)
Finds text elements that contain a specific text.
|
static Predicate |
typable()
Finds all input elements that can be used to enter text.
|
static Predicate |
typable(java.lang.String text)
Finds input elements that can be used to enter text and are labeled with a specific text.
|
static Query |
union(Query... queries)
Creates a union of multiple queries by merging their results.
|
static Predicate |
xPath(java.lang.String selector)
Finds elements that match the given XPath selector.
|
public static Query query(Browser browser, Predicate... predicates)
Browser.query(Predicate...)
.
Examples:
browser.query(contains("result")).findFirst();
searches for elements containing the attribute or
inner text resultbrowser.query(headline()).findFirst();
searches for title elements, i.e. <h1>
, <h2>
, ... <h6>
and any element with a bigger font-size than the default on the current pagebrowser.query(clickable()).findFirst();
searches for all clickable elements like links and buttonsbrowser.query(image("description"), below(typable("mail")).findFirst();
searches for all image elements with the label
description which are below typable elements labeled mailDescription:
Create a new query instance by calling browser.query()
. Predicates can be chained and arbitrarily nested one after another.
To get the matching HtmlElements
or HtmlElement
, call Query.find()
or Query.findFirst()
.
browser
- predicates
- public static Query union(Query... queries)
queries
- the queries for the unionQuery
with merged resultspublic static Predicate and(Predicate... predicates)
predicates
- all of the predicates need to match to return an elementpublic static Predicate or(Predicate... predicates)
predicates
- at least one of the predicates need to match to return an elementpublic static Predicate not(Predicate... predicates)
TODO describe standalone "not" predicates
predicates
- all elements that match the predicates will be removed from the result setpublic static Predicate elements(HtmlElements elements)
HtmlElements
as predicate result.elements
- the elements are directly passed to the result setHtmlElements
public static Predicate select(java.lang.String selector)
Example:
select("div#content > p.info:visible > strong[name=author]")
selector
- the jQuery/CSS selectorSelectPredicate
public static Predicate xPath(java.lang.String selector)
Example:
xpath("//div[id=content]/p[class=info]/strong[name=author]")
selector
- the XPath selectorXPathPredicate
public static Predicate contains(java.lang.String text)
Example:
contains("contact me")
text
- case insensitive textContainsPredicate
public static Predicate text(java.lang.String text)
Example:
text("lorem ipsum")
text
- case insensitive textTextPredicate
public static Predicate text()
TextPredicate
text(String)
public static Predicate headline(java.lang.String text)
Example:
headline("contents")
text
- case insensitive textHeadlinePredicate
public static Predicate headline()
HeadlinePredicate
headline(String)
public static Predicate link(java.lang.String text)
Example:
link("follow me")
text
- case insensitive textLinkPredicate
public static Predicate link()
LinkPredicate
link(String)
public static Predicate clickable(java.lang.String text)
Example:
clickable("search")
text
- case insensitive textClickablePredicate
public static Predicate clickable()
ClickablePredicate
clickable(String)
public static Predicate typable(java.lang.String text)
Example:
typable("email")
text
- case insensitive textTypablePredicate
public static Predicate typable()
TypablePredicate
typable(String)
public static Predicate checkable(java.lang.String text)
Example:
checkable("newsletter")
text
- case insensitive textCheckablePredicate
public static Predicate checkable()
CheckablePredicate
checkable(String)
public static Predicate choosable(java.lang.String text)
Example:
choosable("ingredients")
text
- case insensitive textChoosablePredicate
public static Predicate choosable()
ChoosablePredicate
choosable(String)
public static Predicate datepicker(java.lang.String text)
Example:
datepicker("departure")
text
- case insensitive textDatepickerPredicate
public static Predicate datepicker()
DatepickerPredicate
datepicker(String)
public static Predicate submittable(java.lang.String text)
Example:
submittable("purchase")
text
- case insensitive textSubmittablePredicate
public static Predicate submittable()
SubmittablePredicate
submittable(String)
public static Predicate image(java.lang.String text)
Example:
image("statistics last year")
text
- case insensitive textImagePredicate
public static Predicate image()
ImagePredicate
image(String)
public static Predicate frame(java.lang.String text)
Example:
frame("information")
text
- case insensitive textFramePredicate
public static Predicate color(java.awt.Color color, double tolerance, double dominance)
Tolerance: Lower values mean a lower tolerance regarding the color distance between the given color and the pixels of an element to select it.
Dominance: Lower values mean a lower percentage of pixels containing the specified color needed to select an element.
color
- the result elements have a similar color as the specified Color
tolerance
- the higher the tolerance, the more distant colors are matching.
1
is always true and 0
is only true if the image has enough dominant pixels with that exact colordominance
- the higher the dominance, the less percent of the element can be covered by other colors
0
is always true and 1
is only true if the image has exclusively colors within the tolerance rangeColorPredicate
Tolerance
,
Dominance
public static Predicate color(java.awt.Color color, Tolerance tolerance, Dominance dominance)
color(Color, double, double)
for details.color
- the result elements have a similar color as the specified Color
tolerance
- the higher the tolerance, the more distant colors are matchingdominance
- the higher the dominance, the less percent of the element can be covered by other colorsColorPredicate
public static Predicate color(ColorName colorName, double tolerance, double dominance)
color(Color, double, double)
for details.colorName
- the result elements have a similar color as the specified ColorName
tolerance
- the higher the tolerance, the more distant colors are matchingdominance
- the higher the dominance, the less percent of the element can be covered by other colorsColorPredicate
public static Predicate color(ColorName colorName, Tolerance tolerance, Dominance dominance)
color(Color, double, double)
for details.colorName
- the result elements have a similar color as the specified ColorName
tolerance
- the higher the tolerance, the more distant colors are matchingdominance
- the higher the dominance, the less percent of the element can be covered by other colorsColorPredicate
public static Predicate color(java.awt.Color color)
color(Color, double, double)
for details.color
- the result elements have a similar color as the specified Color
ColorPredicate
public static Predicate color(ColorName colorName)
color(Color, double, double)
for details.colorName
- the result elements have a similar color as the specified ColorName
ColorPredicate
public static Predicate closeTo(DirectionOptions options, Predicate... predicates)
The DirectionOptions
if found elements will be filtered out in case they are visually at another location.
The found elements will be automatically ordered by closeness to the referenceElements.
The distance is calculated by the euclidean measure.
Use the shortcuts of this method if needed. See (above(Predicate...)
, below(Predicate...)
,
leftOf(Predicate...)
and rightOf(Predicate...)
.
Calling Query.find()
will order the result by closeness, so that the first result is the closest element to
the reference element.
options
- the parameters of this predicate, including maximum distance and allowed directionspredicates
- the result elements are close to the elements determined by this predicatesDirectionPredicate
public static Predicate closeTo(DirectionOptions options, HtmlElements elements)
HtmlElements
. See closeTo(Predicate...)
for details.options
- the parameters of this predicate, including maximum distance and allowed directionselements
- the result elements are close to these HtmlElements
DirectionPredicate
closeTo(DirectionOptions, Predicate...)
public static Predicate closeTo(DirectionOptions options, HtmlElement element)
HtmlElement
. See closeTo(Predicate...)
for details.options
- the parameters of this predicate, including maximum distance and allowed directionselement
- the result elements are close to this HtmlElement
DirectionPredicate
closeTo(DirectionOptions, Predicate...)
public static Predicate closeTo(int maxDistance, Predicate... predicates)
closeTo(Predicate...)
for details.maxDistance
- the result elements` allowed maximum distance to the predicate results in pixelspredicates
- the result elements are close to the elements determined by this predicatesDirectionPredicate
closeTo(DirectionOptions, Predicate...)
public static Predicate closeTo(int maxDistance, HtmlElements elements)
HtmlElements
, with a maximum distance. See closeTo(Predicate...)
for details.maxDistance
- the result elements` allowed maximum distance to the predicate results in pixelselements
- the result elements are close to these HtmlElements
DirectionPredicate
closeTo(DirectionOptions, Predicate...)
public static Predicate closeTo(int maxDistance, HtmlElement element)
HtmlElement
, with a maximum distance. See closeTo(Predicate...)
for details.maxDistance
- the result elements` allowed maximum distance to the predicate results in pixelselement
- the result elements are close to this HtmlElement
DirectionPredicate
closeTo(DirectionOptions, Predicate...)
public static Predicate closeTo(Predicate... predicates)
closeTo(Predicate...)
for details.
TODO make constant of 300 pixels configurablepredicates
- the result elements are close to the elements determined by this predicatesDirectionPredicate
closeTo(DirectionOptions, Predicate...)
public static Predicate closeTo(HtmlElements elements)
HtmlElements
, with a maximum distance of 300 pixels. See closeTo(Predicate...)
for details.
TODO make constant of 300 pixels configurableelements
- the result elements are close to these HtmlElements
DirectionPredicate
closeTo(DirectionOptions, Predicate...)
public static Predicate closeTo(HtmlElement element)
HtmlElement
, with a maximum distance of 300 pixels. See closeTo(Predicate...)
for details.
TODO make constant of 300 pixels configurableelement
- the result elements are close to these HtmlElement
DirectionPredicate
closeTo(DirectionOptions, Predicate...)
public static Predicate above(Predicate... predicates)
Elements are above if their bottom y coordinate is equal or lower than the top y coordinate of the reference element.
In addition, the element has to be in horizontal bounds of the reference element.
Example: (visual representation of the web page)
.
----------
- <span> -
----------
---------
- <div> -
---------
--------
- <ul> -
--------
In this example, both the <div>
and the <span>
are above the <ul>
.
Also, the <span>
is above the <div>
, but the <ul>
is not.
See closeTo(DirectionOptions, Predicate...)
for more details.
predicates
- the result elements are above the elements determined by this predicatesDirectionPredicate
closeTo(DirectionOptions, Predicate...)
public static Predicate above(HtmlElements elements)
HtmlElements
. See above(Predicate...)
for details.elements
- the result elements are above these HtmlElements
DirectionPredicate
above(Predicate...)
public static Predicate above(HtmlElement element)
HtmlElement
. See above(Predicate...)
for details.element
- the result elements are above this HtmlElement
DirectionPredicate
above(Predicate...)
public static Predicate below(Predicate... predicates)
Elements are below if their top y coordinate is equal or greater than the bottom y coordinate of the reference element.
In addition, the element has to be in horizontal bounds of the reference element.
Example: (visual representation of the web page)
.
--------
- <ul> -
--------
---------
- <div> -
---------
----------
- <span> -
----------
In this example, the <div>
and the <span>
are below the <ul>
.
Also, the <span>
is below the <div>
, but the <ul>
is not.
See closeTo(DirectionOptions, Predicate...)
for more details.
predicates
- the result elements are above the elements determined by this predicatesDirectionPredicate
closeTo(DirectionOptions, Predicate...)
public static Predicate below(HtmlElements elements)
HtmlElements
. See below(Predicate...)
for details.elements
- the result elements are below these HtmlElements
DirectionPredicate
below(Predicate...)
public static Predicate below(HtmlElement element)
HtmlElement
. See below(Predicate...)
for details.element
- the result elements are below this HtmlElement
DirectionPredicate
below(Predicate...)
public static Predicate leftOf(Predicate... predicates)
Elements are left of if their right x coordinate is equal or lower than the left x coordinate of the reference element.
In addition, the element has to be in vertical bounds of the reference element.
Example: (visual representation of the web page)
.
----------
-------- - <span> -
- <ul> - ----------
-------- ---------
- <div> -
---------
In this example, the <ul>
is left of the <span>
and the <div>
, but the <div>
is
not left of the <span>
, because its right border is overlapping the left border of the <span>
.
See closeTo(DirectionOptions, Predicate...)
for more details.
predicates
- the result elements are above the elements determined by this predicatesDirectionPredicate
closeTo(DirectionOptions, Predicate...)
public static Predicate leftOf(HtmlElements elements)
HtmlElements
. See leftOf(Predicate...)
for details.elements
- the result elements are left of these HtmlElements
DirectionPredicate
leftOf(Predicate...)
public static Predicate leftOf(HtmlElement element)
HtmlElement
. See leftOf(Predicate...)
for details.element
- the result elements are left of this HtmlElement
DirectionPredicate
leftOf(Predicate...)
public static Predicate rightOf(Predicate... predicates)
Elements are right of if their left x coordinate is higher than the right x coordinate of the reference element.
In addition, the element has to be in vertical bounds of the reference element.
Example: (visual representation of the web page)
.
----------
-------- - <span> -
- <ul> - ----------
-------- ---------
- <div> -
---------
In this example, the <span>
and the <div>
are right of the <ul>
, but the <span>
is not right of the <div>
because its left border is overlapping the right border of the <span>
.
See closeTo(DirectionOptions, Predicate...)
for more details.
predicates
- the result elements are above the elements determined by this predicatesDirectionPredicate
closeTo(DirectionOptions, Predicate...)
public static Predicate rightOf(HtmlElements elements)
HtmlElements
. See rightOf(Predicate...)
for details.elements
- the result elements are left of these HtmlElements
DirectionPredicate
rightOf(Predicate...)
public static Predicate rightOf(HtmlElement element)
HtmlElement
. See rightOf(Predicate...)
for details.element
- the result elements are left of this HtmlElement
DirectionPredicate
rightOf(Predicate...)
public static Predicate aboveAll(Predicate... predicates)
Example: (visual representation of the web page)
.
----------
- <span> -
----------
--------- --------
- <div> - - <ul> -
--------- --------
-------- ---------
- <ul> - - <div> -
-------- ---------
In this example, only the <span>
is above all the <ul>
(or <div>
respectively).
See closeTo(DirectionOptions, Predicate...)
for more details.
predicates
- the result elements are above the elements determined by this predicatesDirectionPredicate
closeTo(DirectionOptions, Predicate...)
,
above(Predicate...)
public static Predicate aboveAll(HtmlElements elements)
HtmlElements
.
See aboveAll(Predicate...)
for more details.elements
- the result elements are above all these HtmlElements
DirectionPredicate
aboveAll(Predicate...)
public static Predicate aboveAll(HtmlElement element)
HtmlElement
.
See aboveAll(Predicate...)
for more details.element
- the result elements are above all this HtmlElement
DirectionPredicate
aboveAll(Predicate...)
public static Predicate belowAll(Predicate... predicates)
Example: (visual representation of the web page)
.
-------- ---------
- <ul> - - <div> -
-------- ---------
--------- --------
- <div> - - <ul> -
--------- --------
----------
- <span> -
----------
In this example, only the <span>
is below all the <ul>
(or <div>
respectively).
See closeTo(DirectionOptions, Predicate...)
for more details.
predicates
- the result elements are above the elements determined by this predicatesDirectionPredicate
closeTo(DirectionOptions, Predicate...)
,
below(Predicate...)
public static Predicate belowAll(HtmlElements elements)
HtmlElements
.
See belowAll(Predicate...)
for more details.elements
- the result elements are below all these HtmlElements
DirectionPredicate
belowAll(Predicate...)
public static Predicate belowAll(HtmlElement element)
HtmlElement
.
See belowAll(Predicate...)
for more details.element
- the result elements are below all this HtmlElement
DirectionPredicate
belowAll(Predicate...)
public static Predicate leftOfAll(Predicate... predicates)
Example: (visual representation of the web page)
.
--------
- <ul> -
--------- --------
- <div> -
---------- ---------
- <span> -
---------- ---------
- <ul> -
-------- ---------
- <div> -
---------
In this example, only the <span>
is left of all the <ul>
(or <div>
respectively).
See closeTo(DirectionOptions, Predicate...)
for more details.
predicates
- the result elements are above the elements determined by this predicatesDirectionPredicate
closeTo(DirectionOptions, Predicate...)
,
leftOf(Predicate...)
public static Predicate leftOfAll(HtmlElements elements)
HtmlElements
.
See leftOfAll(Predicate...)
for more details.elements
- the result elements are left of all these HtmlElements
DirectionPredicate
leftOfAll(Predicate...)
public static Predicate leftOfAll(HtmlElement element)
HtmlElement
.
See leftOfAll(Predicate...)
for more details.element
- the result elements are left of all this HtmlElement
DirectionPredicate
leftOfAll(Predicate...)
public static Predicate rightOfAll(Predicate... predicates)
Example: (visual representation of the web page)
.
---------
- <div> -
--------- --------
- <ul> -
-------- ----------
- <span> -
--------- ----------
- <div> -
-------- ---------
- <ul> -
--------
In this example, only the <span>
is right of all the <ul>
(or <div>
respectively).
See closeTo(DirectionOptions, Predicate...)
for more details.
predicates
- the result elements are above the elements determined by this predicatesDirectionPredicate
closeTo(DirectionOptions, Predicate...)
,
rightOf(Predicate...)
public static Predicate rightOfAll(HtmlElements elements)
HtmlElements
.
See rightOfAll(Predicate...)
for more details.elements
- the result elements are right of all these HtmlElements
DirectionPredicate
rightOfAll(Predicate...)
public static Predicate rightOfAll(HtmlElement element)
HtmlElement
.
See rightOfAll(Predicate...)
for more details.element
- the result elements are right of all this HtmlElement
DirectionPredicate
rightOfAll(Predicate...)