Class RelativeLocator
java.lang.Object
org.openqa.selenium.support.locators.RelativeLocator
Used for finding elements by their location on a page, rather than their position on the DOM.
Elements are returned ordered by their proximity to the last anchor element used for finding
them. As an example:
ListWould return allelements = driver.findElements(with(tagName("p")).above(lowest));
p
elements above the WebElement
lowest
sorted by the
proximity to lowest
.
Proximity is determined by simply comparing the distance to the center point of each of the elements in turn. For some non-rectangular shapes (such as paragraphs of text that take more than one line), this may lead to some surprising results.
In addition, be aware that the relative locators all use the "client bounding rect" of elements to determine whether something is "left", "right", "above" or "below" of another. Given the example:
+-----+ | a |---+ +-----+ b | +-----+Where
a
partially overlaps b
, b
is none of "above", "below", "left" or
"right" of a
. This is because of how these are calculated using the box model.
b
's bounding rect has it's left-most edge to the right of a
's bounding rect's right-most
edge, so it is not considered to be "right" of a
. Similar logic applies for the other
directions.-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic RelativeLocator.RelativeBy
Start of a relative locator, finding elements by tag name.
-
Constructor Details
-
RelativeLocator
public RelativeLocator()
-
-
Method Details
-
with
Start of a relative locator, finding elements by tag name.
-