Class 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 elements = driver.findElements(with(tagName("p")).above(lowest));
     
    Would return all 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.
    • Constructor Summary

      Constructors 
      Constructor Description
      RelativeLocator()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static RelativeLocator.RelativeBy with​(org.openqa.selenium.By by)
      Start of a relative locator, finding elements by tag name.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • RelativeLocator

        public RelativeLocator()
    • Method Detail

      • with

        public static RelativeLocator.RelativeBy with​(org.openqa.selenium.By by)
        Start of a relative locator, finding elements by tag name.