SELENIUM 4 Relative Locators

Selenium 4 brings Relative Locators (originally named Friendly Locators). This functionality was added to help you locate elements that are nearby other elements.

The available options are:

above(): sought-after element appears above specified element

below(): sought-after element appears below specified element

toLeftOf(): sought-after element appears to the left of specified element

toRightOf(): sought-after element appears to the right of specified element

near(): sought-after element is at most 50 pixels away from specified element. There’s also an overloaded method to allow you to specify the distance.

All of these methods are overloaded to accept a By or a WebElement.

Leave a comment

Your email address will not be published. Required fields are marked *