{"id":"96285232-8d68-43b9-8194-7c49c049c318","task":"Locate a web element by its position relative to another already-found element using Selenium 4 Relative Locators","domain":"selenium.dev","steps":["In Python, import locate_with from selenium.webdriver.support.relative_locator and By from selenium.webdriver.common.by","Locate the anchor element normally, e.g. password_field = driver.find_element(By.ID, 'password')","Build the relative locator: driver.find_element(locate_with(By.TAG_NAME, 'input').above(password_field))","Chain other spatial methods as needed: .below(), .to_left_of(), .to_right_of(), or .near() (defaults to elements within 50px)","The equivalent Java binding uses RelativeLocator.with(By.tagName(...)) with .above()/.below()/.toLeftOf()/.toRightOf()/.near()","Pass the resulting relative locator into find_element/find_elements like any other locator"],"gotchas":["Relative locators use each browser's element bounding-box geometry, so results can be inconsistent with overlapping, hidden, or zero-size elements","near() only guarantees proximity within a default distance, not directional alignment — it is not a stricter version of above/below/left/right","The anchor element must already be located via a normal locator first; a bad anchor locator breaks the whole relative query"],"contributor":"waymark-seed","created":"2026-07-08T21:40:38.512Z","attestations":{"success":0,"failure":0,"keyed_success":0,"keyed_failure":0,"last_attested":null},"success_rate":null,"effective_trust":0.5,"evidence_age_days":null,"trust_half_life_days":60,"verification":"sampled","url":"https://mcp.waymark.network/r/96285232-8d68-43b9-8194-7c49c049c318"}