Skip to content

Commit 5b7955b

Browse files
committed
Fixes after review
1 parent a06a929 commit 5b7955b

File tree

1 file changed

+8
-9
lines changed
  • src/main/java/io/appium/java_client/pagefactory/bys/builder

1 file changed

+8
-9
lines changed

src/main/java/io/appium/java_client/pagefactory/bys/builder/ByAll.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@
1515

1616
public class ByAll extends org.openqa.selenium.support.pagefactory.ByAll {
1717

18-
private List<By> bys;
18+
private final List<By> bys;
1919

2020
private Function<SearchContext, Optional<WebElement>> getSearchingFunction(By by) {
2121
return input -> {
2222
try {
23-
return input.findElement(by);
23+
return Optional.of(input.findElement(by));
2424
} catch (NoSuchElementException e) {
2525
return Optional.empty();
2626
}
@@ -42,12 +42,11 @@ public ByAll(By[] bys) {
4242

4343
@Override
4444
public WebElement findElement(SearchContext context) {
45-
for (By by : bys) {
46-
Optional<WebElement> element = getSearchingFunction(by).apply(context);
47-
if (element.isPresent()) {
48-
return element.get();
49-
}
50-
}
51-
throw new NoSuchElementException("Cannot locate an element using " + toString());
45+
return bys.stream()
46+
.map(by -> getSearchingFunction(by).apply(context))
47+
.filter(Optional::isPresent)
48+
.findFirst()
49+
.orElseThrow(() -> new NoSuchElementException("Cannot locate an element using " + toString()))
50+
.orElse(null);
5251
}
5352
}

0 commit comments

Comments
 (0)