{"record":{"id":"28115c59e100d6e5","repo":"SeleniumHQ/selenium","slug":"element-or-locator-must-be-given-when-calling-belo","errorCode":null,"errorMessage":"Element or locator must be given when calling below method","messagePattern":"Element or locator must be given when calling below method","errorType":"exception","errorClass":"WebDriverException","httpStatus":null,"severity":"error","filePath":"py/selenium/webdriver/support/relative_locator.py","lineNumber":145,"sourceCode":"\n    def below(self, element_or_locator: WebElement | dict | None = None) -> \"RelativeBy\":\n        \"\"\"Add a filter to look for elements below.\n\n        Args:\n            element_or_locator: Element to look below\n\n        Returns:\n            RelativeBy\n\n        Raises:\n            WebDriverException: If `element_or_locator` is None.\n\n        Example:\n            >>> highest = driver.find_element(By.ID, \"high\")\n            >>> elements = driver.find_elements(locate_with(By.CSS_SELECTOR, \"p\").below(highest))\n        \"\"\"\n        if not element_or_locator:\n            raise WebDriverException(\"Element or locator must be given when calling below method\")\n\n        self.filters.append({\"kind\": \"below\", \"args\": [element_or_locator]})\n        return self\n\n    @overload\n    def to_left_of(self, element_or_locator: WebElement | LocatorType) -> \"RelativeBy\": ...\n\n    @overload\n    def to_left_of(self, element_or_locator: None = None) -> \"NoReturn\": ...\n\n    def to_left_of(self, element_or_locator: WebElement | dict | None = None) -> \"RelativeBy\":\n        \"\"\"Add a filter to look for elements to the left of.\n\n        Args:\n            element_or_locator: Element to look to the left of\n\n        Returns:\n            RelativeBy","sourceCodeStart":127,"sourceCodeEnd":163,"githubUrl":"https://github.com/SeleniumHQ/selenium/blob/aa36b38e696a0909e973bdf5e2f9031ffe842c4b/py/selenium/webdriver/support/relative_locator.py#L127-L163","documentation":"RelativeBy.below requires a non-null element_or_locator; a falsy value raises WebDriverException naming the 'below' method.","triggerScenarios":"Chaining .below(None) or passing an empty dict / unresolved lookup.","commonSituations":"Piping a not-found anchor straight into .below().","solutions":["Resolve and verify the anchor element/locator before chaining .below().","Guard the value before calling.","Use find_element for anchors so a miss surfaces early."],"exampleFix":"# before\nanchor = maybe_find()\nelements = driver.find_elements(locate_with(By.CSS_SELECTOR, \"p\").below(anchor))\n\n# after\nanchor = driver.find_element(By.ID, \"anchor\")\nelements = driver.find_elements(locate_with(By.CSS_SELECTOR, \"p\").below(anchor))","handlingStrategy":"type-guard","validationCode":"if not element_or_locator:\n    raise ValueError(\"anchor required before .below()\")","typeGuard":"from selenium.webdriver.remote.webelement import WebElement\ndef is_anchor(v) -> bool:\n    return isinstance(v, WebElement) or (isinstance(v, dict) and v)","tryCatchPattern":null,"preventionTips":["Assert the anchor is non-None before chaining direction methods.","Resolve anchors with find_element, not optional lookups."],"tags":["relative-locator","validation"],"backgroundTag":null,"analyzedSha":"aa36b38e696a0909e973bdf5e2f9031ffe842c4b","analyzedAt":"2026-08-14T02:32:32.244Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}