File tree Expand file tree Collapse file tree 3 files changed +50
-2
lines changed
src/main/java/io/appium/java_client/pagefactory Expand file tree Collapse file tree 3 files changed +50
-2
lines changed Original file line number Diff line number Diff line change 2323import io .appium .java_client .pagefactory .bys .ContentMappedBy ;
2424import io .appium .java_client .pagefactory .bys .ContentType ;
2525import io .appium .java_client .pagefactory .bys .builder .AppiumByBuilder ;
26+ import io .appium .java_client .pagefactory .bys .builder .ByAll ;
2627import io .appium .java_client .pagefactory .bys .builder .ByChained ;
2728import io .appium .java_client .pagefactory .bys .builder .HowToUseSelectors ;
2829import org .openqa .selenium .By ;
3132import org .openqa .selenium .support .FindAll ;
3233import org .openqa .selenium .support .FindBy ;
3334import org .openqa .selenium .support .FindBys ;
34- import org .openqa .selenium .support .pagefactory .ByAll ;
3535
3636import java .lang .annotation .Annotation ;
3737import java .lang .reflect .AnnotatedElement ;
Original file line number Diff line number Diff line change 2424
2525import org .openqa .selenium .By ;
2626import org .openqa .selenium .support .pagefactory .AbstractAnnotations ;
27- import org .openqa .selenium .support .pagefactory .ByAll ;
2827
2928import java .lang .annotation .Annotation ;
3029import java .lang .reflect .AnnotatedElement ;
Original file line number Diff line number Diff line change 1+ package io .appium .java_client .pagefactory .bys .builder ;
2+
3+ import static com .google .common .base .Preconditions .checkNotNull ;
4+
5+ import org .openqa .selenium .By ;
6+ import org .openqa .selenium .NoSuchElementException ;
7+ import org .openqa .selenium .SearchContext ;
8+ import org .openqa .selenium .WebElement ;
9+
10+ import java .util .function .Function ;
11+
12+
13+ public class ByAll extends org .openqa .selenium .support .pagefactory .ByAll {
14+
15+ private By [] bys ;
16+
17+ private Function <SearchContext , WebElement > getSearchingFunction (By by ) {
18+ return input -> {
19+ try {
20+ return input .findElement (by );
21+ } catch (NoSuchElementException e ) {
22+ return null ;
23+ }
24+ };
25+ }
26+
27+ /**
28+ * @param bys is a set of {@link org.openqa.selenium.By} which forms the all possible searching.
29+ */
30+ public ByAll (By [] bys ) {
31+ super (bys );
32+ checkNotNull (bys );
33+ if (bys .length == 0 ) {
34+ throw new IllegalArgumentException ("By array should not be empty" );
35+ }
36+ this .bys = bys ;
37+ }
38+
39+ @ Override
40+ public WebElement findElement (SearchContext context ) {
41+ for (By by : bys ) {
42+ WebElement element = getSearchingFunction (by ).apply (context );
43+ if (element != null ) {
44+ return element ;
45+ }
46+ }
47+ throw new NoSuchElementException ("Cannot locate an element using " + toString ());
48+ }
49+ }
You can’t perform that action at this time.
0 commit comments