Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions py/selenium/webdriver/remote/webdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -1220,6 +1220,9 @@ def find_element(self, by=By.ID, value=None) -> WebElement:

:rtype: WebElement
"""
if isinstance(by, RelativeBy):
return self.find_elements(by=by, value=value)[0]

if by == By.ID:
by = By.CSS_SELECTOR
value = '[id="%s"]' % value
Expand Down
9 changes: 9 additions & 0 deletions py/test/selenium/webdriver/support/relative_by_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@
from selenium.webdriver.support.relative_locator import with_tag_name, locate_with


def test_should_be_able_to_find_first_one(driver, pages):
pages.load("relative_locators.html")
lowest = driver.find_element(By.ID, "below")

el = driver.find_element(with_tag_name("p").above(lowest))

assert el.get_attribute('id') == "mid"


def test_should_be_able_to_find_elements_above_another(driver, pages):
pages.load("relative_locators.html")
lowest = driver.find_element(By.ID, "below")
Expand Down