Package com.github.loyada.jdollarx
Class BasicPath
- java.lang.Object
-
- com.github.loyada.jdollarx.BasicPath
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
BasicPath.ChildNumber
Allows to define an element that has a predefined number of similar preceding siblings.static class
BasicPath.GlobalOccurrenceNumber
Not to be used directly, but through the utility functions:firstOccurrenceOf(Path)
,lastOccurrenceOf(Path)
,occurrenceNumber(Integer)
static class
BasicPath.PathBuilder
A builder for BasicPath.
-
Field Summary
Fields Modifier and Type Field Description static BasicPath
anchor
An anchor(or "a") elementstatic BasicPath
body
static BasicPath
button
static BasicPath
canvas
static BasicPath
div
static BasicPath
element
Any elementstatic BasicPath
form
static BasicPath
header
Any header elementstatic BasicPath
header1
static BasicPath
header2
static BasicPath
header3
static BasicPath
header4
static BasicPath
header5
static BasicPath
header6
static BasicPath
html
static BasicPath
iframe
static BasicPath
image
static BasicPath
input
static BasicPath
label
static BasicPath
listItem
An "li" elementstatic BasicPath
main
static BasicPath
option
static BasicPath
paragraph
static BasicPath
section
static BasicPath
select
static BasicPath
span
static BasicPath
svg
static BasicPath
table
static BasicPath
td
static BasicPath
textarea
static BasicPath
th
static BasicPath
title
static BasicPath
tr
static BasicPath
unorderedList
An "ul" element
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Path
after(Path path)
The element appears after the given pathPath
afterSibling(Path path)
The element has a preceding sibling that matches to the given Path parameterPath
ancestorOf(Path path)
The element contains the given path, i.e.Path
and(ElementProperty... prop)
Alias equivalent to that().Path
before(Path path)
The element is before the given path parameterPath
beforeSibling(Path path)
The element is a sibling of the given path and appears before itstatic BasicPath.PathBuilder
builder()
static BasicPath.ChildNumber
childNumber(Integer n)
the element is the nth child of its parent.Path
childOf(Path path)
The element is a direct child of the given pathPath
containing(Path path)
The element contains the given path, i.e.Path
contains(Path path)
The element contains the given path, i.e.static BasicPath
customElement(String el)
Create a custom element Path using a simple API instead of the builder pattern.static BasicPath
customNameSpaceElement(String el)
Path
descendantOf(Path path)
The element is inside the given path parameterPath
describedBy(String description)
A useful method to give a readable description to the path, for example: Suppose that instead of describing it's DOM positions and attributes, you prefer to describe it as "search result".static Path
firstOccurrenceOf(Path path)
First global occurrence of an element in the document.Optional<String>
getAlternateXPath()
Optional<String>
getDescribedBy()
List<ElementProperty>
getElementProperties()
Optional<org.openqa.selenium.WebElement>
getUnderlyingSource()
Optional<String>
getXPath()
The Optional xpath is maps to.Optional<String>
getXpathExplanation()
Path
immediatelyAfterSibling(Path path)
The sibling right before the current element matches to the given Path parameterPath
immediatelyBeforeSibling(Path path)
The sibling right after the element matches the given path parameterPath
inside(Path path)
Element that is inside another elementPath
insideTopLevel()
Returns an element that is explicitly inside the document.static Path
lastOccurrenceOf(Path path)
Last global occurrence of an element in the documentstatic BasicPath.GlobalOccurrenceNumber
occurrenceNumber(Integer n)
used in the form : occurrenceNumber(4).of(myElement)).Path
or(Path path)
match more than a single path.Path
parentOf(Path path)
The element is a parent of the given pathstatic Path
textNode(String text)
Define a text node in the DOM, with the given text.Path
that(ElementProperty... prop)
returns a path with the provided properties.String
toString()
Path
withClass(String cssClass)
Equivalent tothis.that(hasClass(cssClass))
Path
withClasses(String... cssClasses)
Equivalent tothis.that(hasClasses(cssClasses))
Path
withGlobalIndex(Integer n)
An alias of:occurrenceNumber(n + 1).of(this)
Path
withText(String txt)
Element with text equals (ignoring case) to txt.Path
withTextContaining(String txt)
Equivalent tothis.that(hasTextContaining(txt))
.
-
-
-
Field Detail
-
element
public static final BasicPath element
Any element
-
div
public static final BasicPath div
-
span
public static final BasicPath span
-
image
public static final BasicPath image
-
listItem
public static final BasicPath listItem
An "li" element
-
button
public static final BasicPath button
-
unorderedList
public static final BasicPath unorderedList
An "ul" element
-
input
public static final BasicPath input
-
anchor
public static final BasicPath anchor
An anchor(or "a") element
-
form
public static final BasicPath form
-
iframe
public static final BasicPath iframe
-
html
public static final BasicPath html
-
body
public static final BasicPath body
-
header1
public static final BasicPath header1
-
header2
public static final BasicPath header2
-
header3
public static final BasicPath header3
-
header4
public static final BasicPath header4
-
header5
public static final BasicPath header5
-
header6
public static final BasicPath header6
-
header
public static final BasicPath header
Any header element
-
title
public static final BasicPath title
-
tr
public static final BasicPath tr
-
td
public static final BasicPath td
-
th
public static final BasicPath th
-
table
public static final BasicPath table
-
select
public static final BasicPath select
-
option
public static final BasicPath option
-
label
public static final BasicPath label
-
section
public static final BasicPath section
-
canvas
public static final BasicPath canvas
-
textarea
public static final BasicPath textarea
-
svg
public static final BasicPath svg
-
main
public static final BasicPath main
-
paragraph
public static final BasicPath paragraph
-
-
Method Detail
-
builder
public static BasicPath.PathBuilder builder()
-
textNode
public static Path textNode(String text)
Define a text node in the DOM, with the given text. Typically you don't need to use it, but it is relevant if you have something like:Male
Female
input.immediatelyBeforeSibling(textNode("Male"));
- Parameters:
text
- the text in the node. Note that it is trimmed, and case insensitive.- Returns:
- a Path of a text node
-
customElement
public static BasicPath customElement(String el)
Create a custom element Path using a simple API instead of the builder pattern. Example:Path myDiv = customElement("div");
- Parameters:
el
- - the element type in W3C. will be used for the toString as well.- Returns:
- a Path representing the element
-
childNumber
public static BasicPath.ChildNumber childNumber(Integer n)
the element is the nth child of its parent. Count starts at 1. For example:childNumber(4).ofType(div.withClass("foo"))
- Parameters:
n
- the index of the child - starting at 1- Returns:
- a ChildNumber instance, which is used with as in the example.
-
occurrenceNumber
public static BasicPath.GlobalOccurrenceNumber occurrenceNumber(Integer n)
used in the form : occurrenceNumber(4).of(myElement)). Return the nth occurrence of the element in the entire document. Count starts at 1. For example:occurrenceNumber(3).of(listItem)
- Parameters:
n
- the number of occurrence- Returns:
- GlobalOccurrenceNumber instance, which is used as in the example.
-
firstOccurrenceOf
public static Path firstOccurrenceOf(Path path)
First global occurrence of an element in the document.- Parameters:
path
- the element to find- Returns:
- a new path with the added constraint
-
lastOccurrenceOf
public static Path lastOccurrenceOf(Path path)
Last global occurrence of an element in the document- Parameters:
path
- the element to find- Returns:
- a new path with the added constraint
-
getXPath
public Optional<String> getXPath()
Description copied from interface:Path
The Optional xpath is maps to. Note that the prefix that marks it is inside the document (for example; "//" as the prefix of the xpath) can be omitted. This is not a concern - it will be added automatically by DollarX when interacting with the browser.
-
getAlternateXPath
public Optional<String> getAlternateXPath()
- Specified by:
getAlternateXPath
in interfacePath
- Returns:
- Should not be used unless you are developing for DollarX.
-
getUnderlyingSource
public Optional<org.openqa.selenium.WebElement> getUnderlyingSource()
- Specified by:
getUnderlyingSource
in interfacePath
- Returns:
- The WebElement that is used as the underlying reference for the Path. In most cases, this Optional is empty.
-
getXpathExplanation
public Optional<String> getXpathExplanation()
- Specified by:
getXpathExplanation
in interfacePath
-
getDescribedBy
public Optional<String> getDescribedBy()
- Specified by:
getDescribedBy
in interfacePath
- Returns:
- optional readable functional description of the Path
-
getElementProperties
public List<ElementProperty> getElementProperties()
- Specified by:
getElementProperties
in interfacePath
- Returns:
- Should not be typically used, unless you are developing for DollarX
-
describedBy
public Path describedBy(String description)
Description copied from interface:Path
A useful method to give a readable description to the path, for example: Suppose that instead of describing it's DOM positions and attributes, you prefer to describe it as "search result". Then you'd call: searchResult = myElement.describedBy("search result"); Now, calling System.out.println(firstOccurrenceOf(searchResult)), will print: "first occurrence of search result" This will replace its toString() result.- Specified by:
describedBy
in interfacePath
- Parameters:
description
- a readable description to that expresses the functionality of the path- Returns:
- a new Path similar to the old one but that is described by the given description
-
or
public Path or(Path path)
match more than a single path. Example: div.or(span) - matches both div and span
-
that
public Path that(ElementProperty... prop)
returns a path with the provided properties. For example: div.that(hasText("abc"), hasClass("foo"));
-
and
public Path and(ElementProperty... prop)
Alias equivalent to that(). Added for readability. Example:div.that(hasClass("a")).and(hasText("foo"));
-
withText
public Path withText(String txt)
Element with text equals (ignoring case) to txt. Equivalent to:path.that(hasText(txt))
-
insideTopLevel
public Path insideTopLevel()
Returns an element that is explicitly inside the document. This is usually not needed - it will be added implicitly when needed.- Specified by:
insideTopLevel
in interfacePath
- Returns:
- a new Path
-
afterSibling
public Path afterSibling(Path path)
The element has a preceding sibling that matches to the given Path parameter- Specified by:
afterSibling
in interfacePath
- Parameters:
path
- - the sibling element that appears before- Returns:
- a new path with the added constraint
-
immediatelyAfterSibling
public Path immediatelyAfterSibling(Path path)
The sibling right before the current element matches to the given Path parameter- Specified by:
immediatelyAfterSibling
in interfacePath
- Parameters:
path
- - the sibling element that appears right before- Returns:
- a new path with the added constraint
-
beforeSibling
public Path beforeSibling(Path path)
The element is a sibling of the given path and appears before it- Specified by:
beforeSibling
in interfacePath
- Parameters:
path
- - the sibling element that appears after- Returns:
- a new path with the added constraint
-
immediatelyBeforeSibling
public Path immediatelyBeforeSibling(Path path)
The sibling right after the element matches the given path parameter- Specified by:
immediatelyBeforeSibling
in interfacePath
- Parameters:
path
- - the sibling element that appears after- Returns:
- a new path with the added constraint
-
childOf
public Path childOf(Path path)
Description copied from interface:Path
The element is a direct child of the given path
-
parentOf
public Path parentOf(Path path)
Description copied from interface:Path
The element is a parent of the given path
-
containing
public Path containing(Path path)
Description copied from interface:Path
The element contains the given path, i.e. the given path parameter is inside the element- Specified by:
containing
in interfacePath
- Parameters:
path
- - the element that is inside our element- Returns:
- a new path with the added constraint
-
contains
public Path contains(Path path)
Description copied from interface:Path
The element contains the given path, i.e. the given path parameter is inside the element
-
ancestorOf
public Path ancestorOf(Path path)
Description copied from interface:Path
The element contains the given path, i.e. the given path parameter is inside the element- Specified by:
ancestorOf
in interfacePath
- Parameters:
path
- - the element that is inside our element- Returns:
- a new path with the added constraint
-
descendantOf
public Path descendantOf(Path path)
The element is inside the given path parameter- Specified by:
descendantOf
in interfacePath
- Parameters:
path
- - the element that is wrapping our element- Returns:
- a new path with the added constraint
-
withGlobalIndex
public Path withGlobalIndex(Integer n)
An alias of:occurrenceNumber(n + 1).of(this)
- Specified by:
withGlobalIndex
in interfacePath
- Parameters:
n
- - the global occurrence index of the path, starting from 0- Returns:
- a new path with the added constraint
-
withClasses
public Path withClasses(String... cssClasses)
Equivalent tothis.that(hasClasses(cssClasses))
- Specified by:
withClasses
in interfacePath
- Parameters:
cssClasses
- the class names- Returns:
- a new path with the added constraint
-
withTextContaining
public Path withTextContaining(String txt)
Equivalent tothis.that(hasTextContaining(txt))
.- Specified by:
withTextContaining
in interfacePath
- Parameters:
txt
- the text to match to. The match is case insensitive.- Returns:
- a new path with the added constraint
-
-