Relative Locators in Selenium

Some buttons located to test the relative locators

Relative Locators are available in Selenium to find nearby elements. Before 2019, this feature was called Friendly Locators. The base function call looks like this

matches = driver.find_elements(with_tag_name("input").to_left_of(element))

You start with an element and then find all elements of a certain type within a certain range. There can be zero, one or many elements nearby. Here is…