2626import java .io .Serializable ;
2727import java .util .List ;
2828
29- @ SuppressWarnings ("serial" )
3029public abstract class AppiumBy extends By implements Remotable {
3130
3231 @ Getter private final Parameters remoteParameters ;
@@ -38,7 +37,6 @@ protected AppiumBy(String selector, String locatorString, String locatorName) {
3837 this .locatorName = locatorName ;
3938 }
4039
41- @ SuppressWarnings ("unchecked" )
4240 @ Override public List <WebElement > findElements (SearchContext context ) {
4341 return context .findElements (this );
4442 }
@@ -48,7 +46,7 @@ protected AppiumBy(String selector, String locatorString, String locatorName) {
4846 }
4947
5048 @ Override public String toString () {
51- return String .format ("AppiumBy .%s: %s" , locatorName , remoteParameters .value ());
49+ return String .format ("%s .%s: %s" , AppiumBy . class . getSimpleName () , locatorName , remoteParameters .value ());
5250 }
5351
5452 /**
@@ -115,6 +113,26 @@ public static By className(final String selector) {
115113 return new ByClassName (selector );
116114 }
117115
116+ /**
117+ * For IOS the element name.
118+ * For Android it is the resource identifier.
119+ * @param selector element id
120+ * @return an instance of {@link ById}
121+ */
122+ public static By id (final String selector ) {
123+ return new ById (selector );
124+ }
125+
126+ /**
127+ * For IOS the element name.
128+ * For Android it is the resource identifier.
129+ * @param selector element id
130+ * @return an instance of {@link ByName}
131+ */
132+ public static By name (final String selector ) {
133+ return new ByName (selector );
134+ }
135+
118136 /**
119137 * This type of locator requires the use of the 'customFindModules' capability and a
120138 * separately-installed element finding plugin.
@@ -165,70 +183,72 @@ public static By iOSNsPredicateString(final String iOSNsPredicateString) {
165183 }
166184
167185 public static class ByAccessibilityId extends AppiumBy implements Serializable {
168-
169186 public ByAccessibilityId (String accessibilityId ) {
170187 super ("accessibility id" , accessibilityId , "accessibilityId" );
171188 }
172189 }
173190
174191 public static class ByAndroidDataMatcher extends AppiumBy implements Serializable {
175-
176192 protected ByAndroidDataMatcher (String locatorString ) {
177193 super ("-android datamatcher" , locatorString , "androidDataMatcher" );
178194 }
179195 }
180196
181197 public static class ByAndroidUIAutomator extends AppiumBy implements Serializable {
182-
183198 public ByAndroidUIAutomator (String uiautomatorText ) {
184199 super ("-android uiautomator" , uiautomatorText , "androidUIAutomator" );
185200 }
186201 }
187202
188203 public static class ByAndroidViewMatcher extends AppiumBy implements Serializable {
189-
190204 protected ByAndroidViewMatcher (String locatorString ) {
191205 super ("-android viewmatcher" , locatorString , "androidViewMatcher" );
192206 }
193207 }
194208
195209 public static class ByAndroidViewTag extends AppiumBy implements Serializable {
196-
197210 public ByAndroidViewTag (String tag ) {
198211 super ("-android viewtag" , tag , "androidViewTag" );
199212 }
200213 }
201214
202- public static class ByClassName extends AppiumBy implements Serializable {
215+ public static class ById extends AppiumBy implements Serializable {
216+ protected ById (String selector ) {
217+ super ("id" , selector , "id" );
218+ }
219+ }
220+
221+ public static class ByName extends AppiumBy implements Serializable {
222+ protected ByName (String selector ) {
223+ super ("name" , selector , "name" );
224+ }
225+ }
203226
227+ public static class ByClassName extends AppiumBy implements Serializable {
204228 protected ByClassName (String selector ) {
205229 super ("class name" , selector , "className" );
206230 }
207231 }
208232
209233 public static class ByCustom extends AppiumBy implements Serializable {
210-
211234 protected ByCustom (String selector ) {
212235 super ("-custom" , selector , "custom" );
213236 }
214237 }
215238
216239 public static class ByImage extends AppiumBy implements Serializable {
217-
218240 protected ByImage (String b64Template ) {
219241 super ("-image" , b64Template , "image" );
220242 }
221243 }
222244
223245 public static class ByIosClassChain extends AppiumBy implements Serializable {
224-
225246 protected ByIosClassChain (String locatorString ) {
226247 super ("-ios class chain" , locatorString , "iOSClassChain" );
227248 }
228249 }
229250
230251 public static class ByIosNsPredicate extends AppiumBy implements Serializable {
231-
232252 protected ByIosNsPredicate (String locatorString ) {
233253 super ("-ios predicate string" , locatorString , "iOSNsPredicate" );
234254 }
0 commit comments