@@ -147,6 +147,18 @@ public static By AndroidViewTag(final String tag) {
147
147
public static By image (final String b64Template ) {
148
148
return new ByImage (b64Template );
149
149
}
150
+
151
+ /**
152
+ * This type of locator requires the use of the 'customFindModules' capability and a
153
+ * separately-installed element finding plugin.
154
+ *
155
+ * @param selector selector to pass to the custom element finding plugin
156
+ * @return an instance of {@link ByCustom}
157
+ * @since Appium 1.9.2
158
+ */
159
+ public static By custom (final String selector ) {
160
+ return new ByCustom (selector );
161
+ }
150
162
151
163
public static class ByIosUIAutomation extends MobileBy implements Serializable {
152
164
@@ -572,6 +584,62 @@ protected ByImage(String b64Template) {
572
584
}
573
585
}
574
586
587
+ public static class ByCustom extends MobileBy implements Serializable {
588
+
589
+ protected ByCustom (String selector ) {
590
+ super (MobileSelector .CUSTOM , selector );
591
+ }
592
+
593
+ /**
594
+ * {@inheritDoc}
595
+ *
596
+ * @throws WebDriverException when current session doesn't support the given selector or when
597
+ * value of the selector is not consistent.
598
+ * @throws IllegalArgumentException when it is impossible to find something on the given
599
+ * {@link SearchContext} instance
600
+ */
601
+ @ SuppressWarnings ("unchecked" )
602
+ @ Override public List <WebElement > findElements (SearchContext context ) {
603
+ Class <?> contextClass = context .getClass ();
604
+
605
+ if (FindsByCustom .class .isAssignableFrom (contextClass )) {
606
+ return FindsByCustom .class .cast (context ).findElementsByCustom (getLocatorString ());
607
+ }
608
+
609
+ if (FindsByFluentSelector .class .isAssignableFrom (contextClass )) {
610
+ return super .findElements (context );
611
+ }
612
+
613
+ throw formIllegalArgumentException (contextClass , FindsByCustom .class , FindsByFluentSelector .class );
614
+ }
615
+
616
+ /**
617
+ * {@inheritDoc}
618
+ *
619
+ * @throws WebDriverException when current session doesn't support the given selector or when
620
+ * value of the selector is not consistent.
621
+ * @throws IllegalArgumentException when it is impossible to find something on the given
622
+ * {@link SearchContext} instance
623
+ */
624
+ @ Override public WebElement findElement (SearchContext context ) {
625
+ Class <?> contextClass = context .getClass ();
626
+
627
+ if (FindsByCustom .class .isAssignableFrom (contextClass )) {
628
+ return FindsByCustom .class .cast (context ).findElementByCustom (getLocatorString ());
629
+ }
630
+
631
+ if (FindsByFluentSelector .class .isAssignableFrom (contextClass )) {
632
+ return super .findElement (context );
633
+ }
634
+
635
+ throw formIllegalArgumentException (contextClass , FindsByCustom .class , FindsByFluentSelector .class );
636
+ }
637
+
638
+ @ Override public String toString () {
639
+ return "By.Custom: " + getLocatorString ();
640
+ }
641
+ }
642
+
575
643
public static class ByAndroidViewTag extends MobileBy implements Serializable {
576
644
577
645
public ByAndroidViewTag (String tag ) {
0 commit comments