@@ -121,6 +121,16 @@ public static By windowsAutomation(final String windowsAutomation) {
121121 return new ByWindowsAutomation (windowsAutomation );
122122 }
123123
124+ /**
125+ * This locator strategy is available in Espresso Driver mode.
126+ * @since Appium 1.8.2 beta
127+ * @param tag is an view tag string
128+ * @return an instance of {@link ByAndroidViewTag}
129+ */
130+ public static By AndroidViewTag (final String tag ) {
131+ return new ByAndroidViewTag (tag );
132+ }
133+
124134 /**
125135 * This locator strategy is available only if OpenCV libraries and
126136 * NodeJS bindings are installed on the server machine.
@@ -561,6 +571,69 @@ protected ByImage(String b64Template) {
561571 return "By.Image: " + getLocatorString ();
562572 }
563573 }
574+
575+ public static class ByAndroidViewTag extends MobileBy implements Serializable {
576+
577+ public ByAndroidViewTag (String tag ) {
578+ super (MobileSelector .ANDROID_VIEWTAG , tag );
579+ }
580+
581+ /**
582+ * {@inheritDoc}
583+ *
584+ * @throws WebDriverException when current session doesn't support the given selector or when
585+ * value of the selector is not consistent.
586+ * @throws IllegalArgumentException when it is impossible to find something on the given
587+ * {@link SearchContext} instance
588+ */
589+ @ SuppressWarnings ("unchecked" )
590+ @ Override
591+ public List <WebElement > findElements (SearchContext context ) throws WebDriverException ,
592+ IllegalArgumentException {
593+ Class <?> contextClass = context .getClass ();
594+
595+ if (FindsByAndroidViewTag .class .isAssignableFrom (contextClass )) {
596+ return FindsByAndroidViewTag .class .cast (context )
597+ .findElementsByAndroidViewTag (getLocatorString ());
598+ }
599+
600+ if (FindsByFluentSelector .class .isAssignableFrom (contextClass )) {
601+ return super .findElements (context );
602+ }
603+
604+ throw formIllegalArgumentException (contextClass , FindsByAndroidViewTag .class ,
605+ FindsByFluentSelector .class );
606+ }
607+
608+ /**
609+ * {@inheritDoc}
610+ *
611+ * @throws WebDriverException when current session doesn't support the given selector or when
612+ * value of the selector is not consistent.
613+ * @throws IllegalArgumentException when it is impossible to find something on the given
614+ * {@link SearchContext} instance
615+ */
616+ @ Override public WebElement findElement (SearchContext context ) throws WebDriverException ,
617+ IllegalArgumentException {
618+ Class <?> contextClass = context .getClass ();
619+
620+ if (FindsByAndroidViewTag .class .isAssignableFrom (contextClass )) {
621+ return FindsByAndroidViewTag .class .cast (context )
622+ .findElementByAndroidViewTag (getLocatorString ());
623+ }
624+
625+ if (FindsByFluentSelector .class .isAssignableFrom (contextClass )) {
626+ return super .findElement (context );
627+ }
628+
629+ throw formIllegalArgumentException (contextClass , FindsByAndroidViewTag .class ,
630+ FindsByFluentSelector .class );
631+ }
632+
633+ @ Override public String toString () {
634+ return "By.AndroidViewTag: " + getLocatorString ();
635+ }
636+ }
564637}
565638
566639
0 commit comments