File tree Expand file tree Collapse file tree 1 file changed +12
-8
lines changed
src/main/java/io/appium/java_client/pagefactory/bys/builder Expand file tree Collapse file tree 1 file changed +12
-8
lines changed Original file line number Diff line number Diff line change 77import org .openqa .selenium .SearchContext ;
88import org .openqa .selenium .WebElement ;
99
10+ import java .util .Arrays ;
11+ import java .util .List ;
12+ import java .util .Optional ;
1013import java .util .function .Function ;
1114
1215
1316public class ByAll extends org .openqa .selenium .support .pagefactory .ByAll {
1417
15- private By [] bys ;
18+ private List < By > bys ;
1619
17- private Function <SearchContext , WebElement > getSearchingFunction (By by ) {
20+ private Function <SearchContext , Optional < WebElement > > getSearchingFunction (By by ) {
1821 return input -> {
1922 try {
2023 return input .findElement (by );
2124 } catch (NoSuchElementException e ) {
22- return null ;
25+ return Optional . empty () ;
2326 }
2427 };
2528 }
@@ -30,18 +33,19 @@ private Function<SearchContext, WebElement> getSearchingFunction(By by) {
3033 public ByAll (By [] bys ) {
3134 super (bys );
3235 checkNotNull (bys );
33- if (bys .length == 0 ) {
36+
37+ this .bys = Arrays .asList (bys );
38+ if (this .bys .isEmpty ()) {
3439 throw new IllegalArgumentException ("By array should not be empty" );
3540 }
36- this .bys = bys ;
3741 }
3842
3943 @ Override
4044 public WebElement findElement (SearchContext context ) {
4145 for (By by : bys ) {
42- WebElement element = getSearchingFunction (by ).apply (context );
43- if (element != null ) {
44- return element ;
46+ Optional < WebElement > element = getSearchingFunction (by ).apply (context );
47+ if (element . isPresent () ) {
48+ return element . get () ;
4549 }
4650 }
4751 throw new NoSuchElementException ("Cannot locate an element using " + toString ());
You can’t perform that action at this time.
0 commit comments