Skip to content

Commit 9e61f06

Browse files
committed
implement functions in java; adjust tests
1 parent 0cc0d04 commit 9e61f06

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

java/src/org/openqa/selenium/support/locators/RelativeLocator.java

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,50 @@ public RelativeBy toRightOf(By locator) {
147147
return simpleDirection("right", locator);
148148
}
149149

150+
public RelativeBy straightAbove(WebElement element) {
151+
Require.nonNull("Element to search straight above of", element);
152+
return simpleDirection("straightAbove", element);
153+
}
154+
155+
public RelativeBy straightAbove(By locator) {
156+
Require.nonNull("Locator", locator);
157+
assertLocatorCanBeSerialized(locator);
158+
return simpleDirection("straightAbove", locator);
159+
}
160+
161+
public RelativeBy straightBelow(WebElement element) {
162+
Require.nonNull("Element to search straight below of", element);
163+
return simpleDirection("straightBelow", element);
164+
}
165+
166+
public RelativeBy straightBelow(By locator) {
167+
Require.nonNull("Locator", locator);
168+
assertLocatorCanBeSerialized(locator);
169+
return simpleDirection("straightBelow", locator);
170+
}
171+
172+
public RelativeBy straightLeftOf(WebElement element) {
173+
Require.nonNull("Element to search straight to the left of", element);
174+
return simpleDirection("straightLeft", element);
175+
}
176+
177+
public RelativeBy straightLeftOf(By locator) {
178+
Require.nonNull("Locator", locator);
179+
assertLocatorCanBeSerialized(locator);
180+
return simpleDirection("straightLeft", locator);
181+
}
182+
183+
public RelativeBy straightRightOf(WebElement element) {
184+
Require.nonNull("Element to search straight to the right of", element);
185+
return simpleDirection("straightRight", element);
186+
}
187+
188+
public RelativeBy straightRightOf(By locator) {
189+
Require.nonNull("Locator", locator);
190+
assertLocatorCanBeSerialized(locator);
191+
return simpleDirection("straightRight", locator);
192+
}
193+
150194
public RelativeBy near(WebElement element) {
151195
Require.nonNull("Element to search near", element);
152196
return near(element, CLOSE_IN_PIXELS);

java/test/org/openqa/selenium/support/locators/RelativeLocatorTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ void shouldBeAbleToFindElementsStraightRightOfAnother() {
184184

185185
WebElement left = driver.findElement(By.id("left"));
186186

187-
List<WebElement> elements = driver.findElements(with(tagName("td")).straightAbove(left));
187+
List<WebElement> elements = driver.findElements(with(tagName("td")).straightRight(left));
188188
List<String> ids =
189189
elements.stream().map(e -> e.getAttribute("id")).collect(Collectors.toList());
190190

0 commit comments

Comments
 (0)