public class RelativeLocator extends java.lang.ObjectUsed 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 all
elements = driver.findElements(with(tagName("p")).above(lowest));
pelements above the
lowestsorted by the proximity to
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
bis 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 Modifier and Type Class Description
Constructors Constructor Description
All Methods Static Methods Concrete Methods Modifier and Type Method Description
with(By by)Start of a relative locator, finding elements by tag name.
public static RelativeLocator.RelativeBy with(By by)Start of a relative locator, finding elements by tag name.