[Python] Why is RelativeBy not accepted in find_elements?

Discussão em 'Python' iniciado por Stack, Julho 28, 2025.

  1. Stack

    Stack Membro Participativo

    Selenium 4 provides RelativeBy that can be produced with locate_with method. Information can be found here under relative locators, and here which is the python api doc.

    However the example code

    >>> lowest = driver.find_element(By.ID, "below")
    >>> elements = driver.find_elements(locate_with(By.CSS_SELECTOR, "p").above(lowest))


    just won't work and my IDE is warning that find_elements method definition don't allow such thing called RelativeBy. When I go check the source code I don't see such method signature as well, and only see

    def find_elements(self, by=By.ID, value: Optional[str] = None) -> List[WebElement]:


    Why do I see a code from the official documentation broken?

    Continue reading...

Compartilhe esta Página