public interface Path
WebElement wrapper = driver.findElement(By.cssSelector("div.foo"));
WebElement field = wrapper.findElement(By.cssSelector(".bar"));
In DollarX it will look like:
final Path wrapper = element.withClass("foo");
final Path field = element.withClass("bad").inside(wrapper);
=======================
1. Once defined, Path values are final and can be reused without cost, as opposed to functions.
2. Creating arbitrarily complex Path is easy this way. It is far more maintainable than using explicit xpath.
3. Creating Paths has nothing to do with the browser.
4. The API offers many alternative ways to define equivalent Paths. The guideline is: If it means the same in English, it is mapped to an equivalent Path. For example, the following are equivalent:
element.that(hasClass("condition").and(isInside(dialog)));
element.that(hasClass("condition")).and(isInside(dialog));
element.inside(dialog).that(hasClass("condition"));
element.withClass("condition").and(isInside(dialog));
element.withClass("condition").and(isContainedIn(dialog));
element.that(hasAncesctor(dialog)).and(hasClass("condition"));
// if you prefer to break the definition to two steps:
Path condition = element.withClass("condition");
condition.inside(dialog);
5. Path::toString returns a string that reads like english and expresses exactly the definition of the path. This is very useful when troubleshooting.
6. To check what is the xpath a Path is mapped to, call path.getXpath().get()
7. Since it can be used as a wrapper of Selenium WebElement, you are not tied to using only DollarX - but can use it interchangeably with straight Selenium WebDriver.
The pattern in DollarX is to define exactly what you want to interact with or assert, as a Path, and then interact with the browser. This maximizes atomicity and performance, and avoid many of the pitfalls involved with interactions with a dynamic SPA. The standard implementation for Path isBasicPath.| Modifier and Type | Method and Description |
|---|---|
Path |
after(Path path)
The element appears after the given path
|
Path |
afterSibling(Path path)
The element is a sibling of the given path, and appears after it
|
Path |
ancestorOf(Path path)
The element contains the given path, i.e.
|
Path |
and(ElementProperty... prop)
Alias equivalent to
that(com.github.loyada.jdollarx.ElementProperty...). |
Path |
before(Path path)
The element appears before the given path
|
Path |
beforeSibling(Path path)
The element is a sibling of the given path, and appears before it
|
Path |
childOf(Path path)
The element is a direct child of the given path
|
Path |
containing(Path path)
The element contains the given path, i.e.
|
Path |
contains(Path path)
The element contains the given path, i.e.
|
Path |
descendantOf(Path path)
The element is contained in the given path element, i.e.
|
Path |
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".
|
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 element matches the given path parameter
|
Path |
immediatelyBeforeSibling(Path path)
The sibling right after the element matches the given path parameter
|
Path |
inside(Path path)
Element that is inside another element
|
Path |
insideTopLevel()
Returns an element that is explicitly inside the document.
|
Path |
or(Path path)
match more than a single path.
|
Path |
parentOf(Path path)
The element is a parent of the given path
|
Path |
that(ElementProperty... prop)
returns a path with the provided properties.
|
Path |
withClass(String cssClass)
The element has the given class name
|
Path |
withClasses(String... cssClasses)
The element has the given class names
|
Path |
withGlobalIndex(Integer index)
Return the nth occurrence of the element in the entire document.
|
Path |
withText(String txt)
Element with text equals (ignoring case) to txt.
|
Path |
withTextContaining(String txt)
The element has text, containing the given txt parameter.
|
Optional<org.openqa.selenium.WebElement> getUnderlyingSource()
Optional<String> getDescribedBy()
Optional<String> getXPath()
Optional<String> getAlternateXPath()
List<ElementProperty> getElementProperties()
Path describedBy(String description)
description - a readable description to that expresses the functionality of the pathPath insideTopLevel()
Path or(Path path)
path - the alternative path to matchPath that(ElementProperty... prop)
prop - - one or more properties. See ElementProperties documentation for detailsPath and(ElementProperty... prop)
that(com.github.loyada.jdollarx.ElementProperty...). Added for readability.
Example:
div.that(hasClass("a")).and(hasText("foo"));
prop - a list of element properties (constraints)Path withText(String txt)
path.that(hasText(txt)) txt - - the text to equal to, ignoring casePath inside(Path path)
path - - the containing elementPath afterSibling(Path path)
path - - the sibling element that appears beforePath immediatelyAfterSibling(Path path)
path - - the sibling element that appears afterPath after(Path path)
path - - the element that appear beforePath beforeSibling(Path path)
path - - the sibling element that appears afterPath immediatelyBeforeSibling(Path path)
path - - the sibling element that appears afterPath before(Path path)
path - - the element that appear afterPath childOf(Path path)
path - - the parent elementPath parentOf(Path path)
path - - the child elementPath containing(Path path)
path - - the element that is inside our elementPath contains(Path path)
path - - the element that is inside our elementPath ancestorOf(Path path)
path - - the element that is inside our elementPath descendantOf(Path path)
path - - the element that is wrapping our elementPath withGlobalIndex(Integer index)
index - the number of occurrencePath withClass(String cssClass)
cssClass - the class namePath withClasses(String... cssClasses)
cssClasses - the class namesCopyright © 2018. All rights reserved.