Class RelativeLocator
- java.lang.Object
-
- org.openqa.selenium.support.locators.RelativeLocator
-
public class RelativeLocator extends java.lang.Object
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:List
Would return allelements = driver.findElements(with(tagName("p")).above(lowest)); p
elements above theWebElement
lowest
sorted by the proximity tolowest
.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 | +-----+
Wherea
partially overlapsb
,b
is none of "above", "below", "left" or "right" ofa
. 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 ofa
's bounding rect's right-most edge, so it is not considered to be "right" ofa
. Similar logic applies for the other directions.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
RelativeLocator.RelativeBy
-
Constructor Summary
Constructors Constructor Description RelativeLocator()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static RelativeLocator.RelativeBy
with(By by)
Start of a relative locator, finding elements by tag name.
-
-
-
Method Detail
-
with
public static RelativeLocator.RelativeBy with(By by)
Start of a relative locator, finding elements by tag name.
-
-