BasicPath

public final class BasicPath implements Path

The standard implementation of Path in DollarX

Fields

anchor

public static final BasicPath anchor

An anchor(or “a”) element

body

public static final BasicPath body

button

public static final BasicPath button

canvas

public static final BasicPath canvas

div

public static final BasicPath div

element

public static final BasicPath element

Any element

form

public static final BasicPath form

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

html

public static final BasicPath html

iframe

public static final BasicPath iframe

image

public static final BasicPath image

input

public static final BasicPath input

label

public static final BasicPath label

listItem

public static final BasicPath listItem

An “li” element

main

public static final BasicPath main

option

public static final BasicPath option

paragraph

public static final BasicPath paragraph

section

public static final BasicPath section

select

public static final BasicPath select

span

public static final BasicPath span

svg

public static final BasicPath svg

table

public static final BasicPath table

td

public static final BasicPath td

textarea

public static final BasicPath textarea

th

public static final BasicPath th

title

public static final BasicPath title

tr

public static final BasicPath tr

unorderedList

public static final BasicPath unorderedList

An “ul” element

Methods

after

public Path after(Path path)

The element appears after the given path

Parameters:
  • path
    • the element that appear before
Returns:

a new path with the added constraint

afterSibling

public Path afterSibling(Path path)

The element has a preceding sibling that matches to the given Path parameter

Parameters:
  • path
    • the sibling element that appears before
Returns:

a new path with the added constraint

ancestorOf

public Path ancestorOf(Path path)
Parameters:
  • path
    • the element that is inside our element
Returns:

a new path with the added constraint

and

public Path and(ElementProperty... prop)

Alias equivalent to that(). Added for readability. Example:

div.that(hasClass("a")).and(hasText("foo"));
Parameters:
  • prop – a list of element properties (constraints)
Returns:

a new Path

before

public Path before(Path path)

The element is before the given path parameter

Parameters:
  • path
    • the element that appear after
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

Parameters:
  • path
    • the sibling element that appears after
Returns:

a new path with the added constraint

builder

public static PathBuilder builder()

childNumber

public static 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.

childOf

public Path childOf(Path path)
Parameters:
  • path
    • the parent element
Returns:

a new path with the added constraint

containing

public Path containing(Path path)
Parameters:
  • path
    • the element that is inside our element
Returns:

a new path with the added constraint

contains

public Path contains(Path path)
Parameters:
  • path
    • the element that is inside our element
Returns:

a new path with the added constraint

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

customNameSpaceElement

public static BasicPath customNameSpaceElement(String el)

descendantOf

public Path descendantOf(Path path)

The element is inside the given path parameter

Parameters:
  • path
    • the element that is wrapping our element
Returns:

a new path with the added constraint

describedBy

public Path describedBy(String description)

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

getAlternateXPath

public Optional<String> getAlternateXPath()

getDescribedBy

public Optional<String> getDescribedBy()

getElementProperties

public List<ElementProperty> getElementProperties()

getUnderlyingSource

public Optional<WebElement> getUnderlyingSource()

getXPath

public Optional<String> getXPath()

getXpathExplanation

public Optional<String> getXpathExplanation()

immediatelyAfterSibling

public Path immediatelyAfterSibling(Path path)

The sibling right before the current element matches to the given Path parameter

Parameters:
  • path
    • the sibling element that appears right before
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

Parameters:
  • path
    • the sibling element that appears after
Returns:

a new path with the added constraint

inside

public Path inside(Path path)

Element that is inside another element

Parameters:
  • path
    • the containing element
Returns:

a new Path with the added constraint

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.

Returns:a new Path

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

occurrenceNumber

public static 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.

or

public Path or(Path path)

match more than a single path. Example: div.or(span) - matches both div and span

Parameters:
  • path – the alternative path to match
Returns:

returns a new path that matches both the original one and the given parameter

parentOf

public Path parentOf(Path path)
Parameters:
  • path
    • the child element
Returns:

a new path with the added constraint

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

that

public Path that(ElementProperty... prop)

returns a path with the provided properties. For example: div.that(hasText(“abc”), hasClass(“foo”));

Parameters:
  • prop
    • one or more properties. See ElementProperties documentation for details
Returns:

a new path with the added constraints

toString

public String toString()

withClass

public Path withClass(String cssClass)

Equivalent to this.that(hasClass(cssClass))

Parameters:
  • cssClass – the class name
Returns:

a new path with the added constraint

withClasses

public Path withClasses(String... cssClasses)

Equivalent to this.that(hasClasses(cssClasses))

Parameters:
  • cssClasses – the class names
Returns:

a new path with the added constraint

withGlobalIndex

public Path withGlobalIndex(Integer n)

An alias of: occurrenceNumber(n + 1).of(this)

Parameters:
  • n
    • the global occurrence index of the path, starting from 0
Returns:

a new path with the added constraint

withText

public Path withText(String txt)

Element with text equals (ignoring case) to txt. Equivalent to:

path.that(hasText(txt))
Parameters:
  • txt
    • the text to equal to, ignoring case
Returns:

a new Path with the added constraint

withTextContaining

public Path withTextContaining(String txt)

Equivalent to this.that(hasTextContaining(txt)).

Parameters:
  • txt – the text to match to. The match is case insensitive.
Returns:

a new path with the added constraint