File tree Expand file tree Collapse file tree 1 file changed +8
-9
lines changed
src/main/java/io/appium/java_client/pagefactory/bys/builder Expand file tree Collapse file tree 1 file changed +8
-9
lines changed Original file line number Diff line number Diff line change 1515
1616public 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}
You can’t perform that action at this time.
0 commit comments