Best io.appium code snippet using io.appium.java_client.MobileBy.ByAndroidViewTag
MobileBy.java
Source:MobileBy.java
1/*2 * Licensed under the Apache License, Version 2.0 (the "License");3 * you may not use this file except in compliance with the License.4 * See the NOTICE file distributed with this work for additional5 * information regarding copyright ownership.6 * You may obtain a copy of the License at7 *8 * http://www.apache.org/licenses/LICENSE-2.09 *10 * Unless required by applicable law or agreed to in writing, software11 * distributed under the License is distributed on an "AS IS" BASIS,12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.13 * See the License for the specific language governing permissions and14 * limitations under the License.15 */16package io.appium.java_client;17import lombok.AccessLevel;18import lombok.Getter;19import org.apache.commons.lang3.StringUtils;20import org.openqa.selenium.By;21import org.openqa.selenium.SearchContext;22import org.openqa.selenium.WebDriverException;23import org.openqa.selenium.WebElement;24import java.io.Serializable;25import java.util.List;26@SuppressWarnings("serial")27public abstract class MobileBy extends By {28 private static final String ERROR_TEXT = "The class %s of the given context "29 + "doesn't implement %s nor %s. Sorry. It is impossible to find something.";30 @Getter(AccessLevel.PROTECTED) private final String locatorString;31 private final MobileSelector selector;32 private static IllegalArgumentException formIllegalArgumentException(Class<?> givenClass,33 Class<?> class1, Class<?> class2) {34 return new IllegalArgumentException(String.format(ERROR_TEXT, givenClass.getCanonicalName(),35 class1.getCanonicalName(), class2.getCanonicalName()));36 }37 protected MobileBy(MobileSelector selector, String locatorString) {38 if (StringUtils.isBlank(locatorString)) {39 throw new IllegalArgumentException("Must supply a not empty locator value.");40 }41 this.locatorString = locatorString;42 this.selector = selector;43 }44 @SuppressWarnings("unchecked")45 @Override public List<WebElement> findElements(SearchContext context) {46 return (List<WebElement>) ((FindsByFluentSelector<?>) context)47 .findElements(selector.toString(), getLocatorString());48 }49 @Override public WebElement findElement(SearchContext context) {50 return ((FindsByFluentSelector<?>) context)51 .findElement(selector.toString(), getLocatorString());52 }53 /**54 * Refer to https://developer.android.com/training/testing/ui-automator55 * @param uiautomatorText is Android UIAutomator string56 * @return an instance of {@link io.appium.java_client.MobileBy.ByAndroidUIAutomator}57 */58 public static By AndroidUIAutomator(final String uiautomatorText) {59 return new ByAndroidUIAutomator(uiautomatorText);60 }61 /**62 * About Android accessibility63 * https://developer.android.com/intl/ru/training/accessibility/accessible-app.html64 * About iOS accessibility65 * https://developer.apple.com/library/ios/documentation/UIKit/Reference/66 * UIAccessibilityIdentification_Protocol/index.html67 * @param accessibilityId id is a convenient UI automation accessibility Id.68 * @return an instance of {@link io.appium.java_client.MobileBy.ByAndroidUIAutomator}69 */70 public static By AccessibilityId(final String accessibilityId) {71 return new ByAccessibilityId(accessibilityId);72 }73 /**74 * This locator strategy is available in XCUITest Driver mode.75 * @param iOSClassChainString is a valid class chain locator string.76 * See <a href="https://github.com/facebookarchive/WebDriverAgent/wiki/Class-Chain-Queries-Construction-Rules">77 * the documentation</a> for more details78 * @return an instance of {@link io.appium.java_client.MobileBy.ByIosClassChain}79 */80 public static By iOSClassChain(final String iOSClassChainString) {81 return new ByIosClassChain(iOSClassChainString);82 }83 /**84 * This locator strategy is only available in Espresso Driver mode.85 * @param dataMatcherString is a valid json string detailing hamcrest matcher for Espresso onData().86 * See <a href="http://appium.io/docs/en/writing-running-appium/android/espresso-datamatcher-selector/">87 * the documentation</a> for more details88 * @return an instance of {@link io.appium.java_client.MobileBy.ByAndroidDataMatcher}89 */90 public static By androidDataMatcher(final String dataMatcherString) {91 return new ByAndroidDataMatcher(dataMatcherString);92 }93 /**94 * This locator strategy is only available in Espresso Driver mode.95 * @param viewMatcherString is a valid json string detailing hamcrest matcher for Espresso onView().96 * See <a href="http://appium.io/docs/en/writing-running-appium/android/espresso-datamatcher-selector/">97 * the documentation</a> for more details98 * @return an instance of {@link io.appium.java_client.MobileBy.ByAndroidViewMatcher}99 */100 public static By androidViewMatcher(final String viewMatcherString) {101 return new ByAndroidViewMatcher(viewMatcherString);102 }103 /**104 * This locator strategy is available in XCUITest Driver mode.105 * @param iOSNsPredicateString is an an iOS NsPredicate String106 * @return an instance of {@link io.appium.java_client.MobileBy.ByIosNsPredicate}107 */108 public static By iOSNsPredicateString(final String iOSNsPredicateString) {109 return new ByIosNsPredicate(iOSNsPredicateString);110 }111 public static By windowsAutomation(final String windowsAutomation) {112 return new ByWindowsAutomation(windowsAutomation);113 }114 /**115 * This locator strategy is available in Espresso Driver mode.116 * @since Appium 1.8.2 beta117 * @param tag is an view tag string118 * @return an instance of {@link ByAndroidViewTag}119 */120 public static By AndroidViewTag(final String tag) {121 return new ByAndroidViewTag(tag);122 }123 /**124 * This locator strategy is available only if OpenCV libraries and125 * NodeJS bindings are installed on the server machine.126 *127 * @see <a href="https://github.com/appium/appium/blob/master/docs/en/writing-running-appium/image-comparison.md">128 * The documentation on Image Comparison Features</a>129 * @see <a href="https://github.com/appium/appium-base-driver/blob/master/lib/basedriver/device-settings.js">130 * The settings available for lookup fine-tuning</a>131 * @since Appium 1.8.2132 * @param b64Template base64-encoded template image string. Supported image formats are the same133 * as for OpenCV library.134 * @return an instance of {@link ByImage}135 */136 public static By image(final String b64Template) {137 return new ByImage(b64Template);138 }139 /**140 * This type of locator requires the use of the 'customFindModules' capability and a141 * separately-installed element finding plugin.142 *143 * @param selector selector to pass to the custom element finding plugin144 * @return an instance of {@link ByCustom}145 * @since Appium 1.9.2146 */147 public static By custom(final String selector) {148 return new ByCustom(selector);149 }150 public static class ByAndroidUIAutomator extends MobileBy implements Serializable {151 public ByAndroidUIAutomator(String uiautomatorText) {152 super(MobileSelector.ANDROID_UI_AUTOMATOR, uiautomatorText);153 }154 /**155 * {@inheritDoc}156 *157 * @throws WebDriverException when current session doesn't support the given selector or when158 * value of the selector is not consistent.159 * @throws IllegalArgumentException when it is impossible to find something on the given160 * {@link SearchContext} instance161 */162 @SuppressWarnings("unchecked")163 @Override164 public List<WebElement> findElements(SearchContext context) throws WebDriverException,165 IllegalArgumentException {166 Class<?> contextClass = context.getClass();167 if (FindsByAndroidUIAutomator.class.isAssignableFrom(contextClass)) {168 return FindsByAndroidUIAutomator.class.cast(context)169 .findElementsByAndroidUIAutomator(getLocatorString());170 }171 if (FindsByFluentSelector.class.isAssignableFrom(contextClass)) {172 return super.findElements(context);173 }174 throw formIllegalArgumentException(contextClass, FindsByAndroidUIAutomator.class,175 FindsByFluentSelector.class);176 }177 /**178 * {@inheritDoc}179 *180 * @throws WebDriverException when current session doesn't support the given selector or when181 * value of the selector is not consistent.182 * @throws IllegalArgumentException when it is impossible to find something on the given183 * {@link SearchContext} instance184 */185 @Override public WebElement findElement(SearchContext context) throws WebDriverException,186 IllegalArgumentException {187 Class<?> contextClass = context.getClass();188 if (FindsByAndroidUIAutomator.class.isAssignableFrom(contextClass)) {189 return FindsByAndroidUIAutomator.class.cast(context)190 .findElementByAndroidUIAutomator(getLocatorString());191 }192 if (FindsByFluentSelector.class.isAssignableFrom(contextClass)) {193 return super.findElement(context);194 }195 throw formIllegalArgumentException(contextClass, FindsByAndroidUIAutomator.class,196 FindsByFluentSelector.class);197 }198 @Override public String toString() {199 return "By.AndroidUIAutomator: " + getLocatorString();200 }201 }202 public static class ByAccessibilityId extends MobileBy implements Serializable {203 public ByAccessibilityId(String accessibilityId) {204 super(MobileSelector.ACCESSIBILITY, accessibilityId);205 }206 /**207 * {@inheritDoc}208 *209 * @throws WebDriverException when current session doesn't support the given selector or when210 * value of the selector is not consistent.211 * @throws IllegalArgumentException when it is impossible to find something on the given212 * {@link SearchContext} instance213 */214 @SuppressWarnings("unchecked")215 @Override216 public List<WebElement> findElements(SearchContext context) throws WebDriverException,217 IllegalArgumentException {218 Class<?> contextClass = context.getClass();219 if (FindsByAccessibilityId.class.isAssignableFrom(contextClass)) {220 return FindsByAccessibilityId.class.cast(context)221 .findElementsByAccessibilityId(getLocatorString());222 }223 if (FindsByFluentSelector.class.isAssignableFrom(contextClass)) {224 return super.findElements(context);225 }226 throw formIllegalArgumentException(contextClass, FindsByAccessibilityId.class,227 FindsByFluentSelector.class);228 }229 /**230 * {@inheritDoc}231 *232 * @throws WebDriverException when current session doesn't support the given selector or when233 * value of the selector is not consistent.234 * @throws IllegalArgumentException when it is impossible to find something on the given235 * {@link SearchContext} instance236 */237 @Override public WebElement findElement(SearchContext context) throws WebDriverException,238 IllegalArgumentException {239 Class<?> contextClass = context.getClass();240 if (FindsByAccessibilityId.class.isAssignableFrom(contextClass)) {241 return FindsByAccessibilityId.class.cast(context)242 .findElementByAccessibilityId(getLocatorString());243 }244 if (FindsByFluentSelector.class.isAssignableFrom(contextClass)) {245 return super.findElement(context);246 }247 throw formIllegalArgumentException(contextClass, FindsByAccessibilityId.class,248 FindsByFluentSelector.class);249 }250 @Override public String toString() {251 return "By.AccessibilityId: " + getLocatorString();252 }253 }254 public static class ByIosClassChain extends MobileBy implements Serializable {255 protected ByIosClassChain(String locatorString) {256 super(MobileSelector.IOS_CLASS_CHAIN, locatorString);257 }258 /**259 * {@inheritDoc}260 *261 * @throws WebDriverException when current session doesn't support the given selector or when262 * value of the selector is not consistent.263 * @throws IllegalArgumentException when it is impossible to find something on the given264 * {@link SearchContext} instance265 */266 @SuppressWarnings("unchecked")267 @Override public List<WebElement> findElements(SearchContext context) {268 Class<?> contextClass = context.getClass();269 if (FindsByIosClassChain.class.isAssignableFrom(contextClass)) {270 return FindsByIosClassChain.class.cast(context)271 .findElementsByIosClassChain(getLocatorString());272 }273 if (FindsByFluentSelector.class.isAssignableFrom(contextClass)) {274 return super.findElements(context);275 }276 throw formIllegalArgumentException(contextClass, FindsByIosClassChain.class,277 FindsByFluentSelector.class);278 }279 /**280 * {@inheritDoc}281 *282 * @throws WebDriverException when current session doesn't support the given selector or when283 * value of the selector is not consistent.284 * @throws IllegalArgumentException when it is impossible to find something on the given285 * {@link SearchContext} instance286 */287 @Override public WebElement findElement(SearchContext context) {288 Class<?> contextClass = context.getClass();289 if (FindsByIosClassChain.class.isAssignableFrom(contextClass)) {290 return FindsByIosClassChain.class.cast(context)291 .findElementByIosClassChain(getLocatorString());292 }293 if (FindsByFluentSelector.class.isAssignableFrom(contextClass)) {294 return super.findElement(context);295 }296 throw formIllegalArgumentException(contextClass, FindsByIosClassChain.class,297 FindsByFluentSelector.class);298 }299 @Override public String toString() {300 return "By.IosClassChain: " + getLocatorString();301 }302 }303 public static class ByAndroidDataMatcher extends MobileBy implements Serializable {304 protected ByAndroidDataMatcher(String locatorString) {305 super(MobileSelector.ANDROID_DATA_MATCHER, locatorString);306 }307 /**308 * {@inheritDoc}309 *310 * @throws WebDriverException when current session doesn't support the given selector or when311 * value of the selector is not consistent.312 * @throws IllegalArgumentException when it is impossible to find something on the given313 * {@link SearchContext} instance314 */315 @SuppressWarnings("unchecked")316 @Override public List<WebElement> findElements(SearchContext context) {317 Class<?> contextClass = context.getClass();318 if (FindsByAndroidDataMatcher.class.isAssignableFrom(contextClass)) {319 return FindsByAndroidDataMatcher.class.cast(context)320 .findElementsByAndroidDataMatcher(getLocatorString());321 }322 if (FindsByFluentSelector.class.isAssignableFrom(contextClass)) {323 return super.findElements(context);324 }325 throw formIllegalArgumentException(contextClass, FindsByAndroidDataMatcher.class,326 FindsByFluentSelector.class);327 }328 /**329 * {@inheritDoc}330 *331 * @throws WebDriverException when current session doesn't support the given selector or when332 * value of the selector is not consistent.333 * @throws IllegalArgumentException when it is impossible to find something on the given334 * {@link SearchContext} instance335 */336 @Override public WebElement findElement(SearchContext context) {337 Class<?> contextClass = context.getClass();338 if (FindsByAndroidDataMatcher.class.isAssignableFrom(contextClass)) {339 return FindsByAndroidDataMatcher.class.cast(context)340 .findElementByAndroidDataMatcher(getLocatorString());341 }342 if (FindsByFluentSelector.class.isAssignableFrom(contextClass)) {343 return super.findElement(context);344 }345 throw formIllegalArgumentException(contextClass, FindsByAndroidDataMatcher.class,346 FindsByFluentSelector.class);347 }348 @Override public String toString() {349 return "By.FindsByAndroidDataMatcher: " + getLocatorString();350 }351 }352 public static class ByAndroidViewMatcher extends MobileBy implements Serializable {353 protected ByAndroidViewMatcher(String locatorString) {354 super(MobileSelector.ANDROID_VIEW_MATCHER, locatorString);355 }356 /**357 * {@inheritDoc}358 *359 * @throws WebDriverException when current session doesn't support the given selector or when360 * value of the selector is not consistent.361 * @throws IllegalArgumentException when it is impossible to find something on the given362 * {@link SearchContext} instance363 */364 @SuppressWarnings("unchecked")365 @Override public List<WebElement> findElements(SearchContext context) {366 Class<?> contextClass = context.getClass();367 if (FindsByAndroidViewMatcher.class.isAssignableFrom(contextClass)) {368 return FindsByAndroidViewMatcher.class.cast(context)369 .findElementsByAndroidViewMatcher(getLocatorString());370 }371 if (FindsByFluentSelector.class.isAssignableFrom(contextClass)) {372 return super.findElements(context);373 }374 throw formIllegalArgumentException(contextClass, FindsByAndroidViewMatcher.class,375 FindsByFluentSelector.class);376 }377 /**378 * {@inheritDoc}379 *380 * @throws WebDriverException when current session doesn't support the given selector or when381 * value of the selector is not consistent.382 * @throws IllegalArgumentException when it is impossible to find something on the given383 * {@link SearchContext} instance384 */385 @Override public WebElement findElement(SearchContext context) {386 Class<?> contextClass = context.getClass();387 if (FindsByAndroidViewMatcher.class.isAssignableFrom(contextClass)) {388 return FindsByAndroidViewMatcher.class.cast(context)389 .findElementByAndroidViewMatcher(getLocatorString());390 }391 if (FindsByFluentSelector.class.isAssignableFrom(contextClass)) {392 return super.findElement(context);393 }394 throw formIllegalArgumentException(contextClass, FindsByAndroidViewMatcher.class,395 FindsByFluentSelector.class);396 }397 @Override public String toString() {398 return "By.FindsByAndroidViewMatcher: " + getLocatorString();399 }400 }401 public static class ByIosNsPredicate extends MobileBy implements Serializable {402 protected ByIosNsPredicate(String locatorString) {403 super(MobileSelector.IOS_PREDICATE_STRING, locatorString);404 }405 /**406 * {@inheritDoc}407 *408 * @throws WebDriverException when current session doesn't support the given selector or when409 * value of the selector is not consistent.410 * @throws IllegalArgumentException when it is impossible to find something on the given411 * {@link SearchContext} instance412 */413 @SuppressWarnings("unchecked")414 @Override public List<WebElement> findElements(SearchContext context) {415 Class<?> contextClass = context.getClass();416 if (FindsByIosNSPredicate.class.isAssignableFrom(contextClass)) {417 return FindsByIosNSPredicate.class.cast(context)418 .findElementsByIosNsPredicate(getLocatorString());419 }420 if (FindsByFluentSelector.class.isAssignableFrom(contextClass)) {421 return super.findElements(context);422 }423 throw formIllegalArgumentException(contextClass, FindsByIosNSPredicate.class,424 FindsByFluentSelector.class);425 }426 /**427 * {@inheritDoc}428 *429 * @throws WebDriverException when current session doesn't support the given selector or when430 * value of the selector is not consistent.431 * @throws IllegalArgumentException when it is impossible to find something on the given432 * {@link SearchContext} instance433 */434 @Override public WebElement findElement(SearchContext context) {435 Class<?> contextClass = context.getClass();436 if (FindsByIosNSPredicate.class.isAssignableFrom(contextClass)) {437 return FindsByIosNSPredicate.class.cast(context)438 .findElementByIosNsPredicate(getLocatorString());439 }440 if (FindsByFluentSelector.class.isAssignableFrom(contextClass)) {441 return super.findElement(context);442 }443 throw formIllegalArgumentException(contextClass, FindsByIosNSPredicate.class,444 FindsByFluentSelector.class);445 }446 @Override public String toString() {447 return "By.IosNsPredicate: " + getLocatorString();448 }449 }450 public static class ByWindowsAutomation extends MobileBy implements Serializable {451 protected ByWindowsAutomation(String locatorString) {452 super(MobileSelector.WINDOWS_UI_AUTOMATION, locatorString);453 }454 /**455 * {@inheritDoc}456 *457 * @throws WebDriverException when current session doesn't support the given selector or when458 * value of the selector is not consistent.459 * @throws IllegalArgumentException when it is impossible to find something on the given460 * {@link SearchContext} instance461 */462 @SuppressWarnings("unchecked")463 @Override public List<WebElement> findElements(SearchContext context) {464 Class<?> contextClass = context.getClass();465 if (FindsByWindowsAutomation.class.isAssignableFrom(contextClass)) {466 return FindsByWindowsAutomation.class.cast(context)467 .findElementsByWindowsUIAutomation(getLocatorString());468 }469 if (FindsByFluentSelector.class.isAssignableFrom(contextClass)) {470 return super.findElements(context);471 }472 throw formIllegalArgumentException(contextClass, FindsByWindowsAutomation.class,473 FindsByFluentSelector.class);474 }475 /**476 * {@inheritDoc}477 *478 * @throws WebDriverException when current session doesn't support the given selector or when479 * value of the selector is not consistent.480 * @throws IllegalArgumentException when it is impossible to find something on the given481 * {@link SearchContext} instance482 */483 @Override public WebElement findElement(SearchContext context) {484 Class<?> contextClass = context.getClass();485 if (FindsByWindowsAutomation.class.isAssignableFrom(contextClass)) {486 return FindsByWindowsAutomation.class.cast(context)487 .findElementByWindowsUIAutomation(getLocatorString());488 }489 if (FindsByFluentSelector.class.isAssignableFrom(contextClass)) {490 return super.findElement(context);491 }492 throw formIllegalArgumentException(contextClass, FindsByIosNSPredicate.class,493 FindsByWindowsAutomation.class);494 }495 }496 public static class ByImage extends MobileBy implements Serializable {497 protected ByImage(String b64Template) {498 super(MobileSelector.IMAGE, b64Template);499 }500 /**501 * {@inheritDoc}502 *503 * @throws WebDriverException when current session doesn't support the given selector or when504 * value of the selector is not consistent.505 * @throws IllegalArgumentException when it is impossible to find something on the given506 * {@link SearchContext} instance507 */508 @SuppressWarnings("unchecked")509 @Override public List<WebElement> findElements(SearchContext context) {510 Class<?> contextClass = context.getClass();511 if (FindsByImage.class.isAssignableFrom(contextClass)) {512 return FindsByImage.class.cast(context).findElementsByImage(getLocatorString());513 }514 if (FindsByFluentSelector.class.isAssignableFrom(contextClass)) {515 return super.findElements(context);516 }517 throw formIllegalArgumentException(contextClass, FindsByImage.class, FindsByFluentSelector.class);518 }519 /**520 * {@inheritDoc}521 *522 * @throws WebDriverException when current session doesn't support the given selector or when523 * value of the selector is not consistent.524 * @throws IllegalArgumentException when it is impossible to find something on the given525 * {@link SearchContext} instance526 */527 @Override public WebElement findElement(SearchContext context) {528 Class<?> contextClass = context.getClass();529 if (FindsByImage.class.isAssignableFrom(contextClass)) {530 return FindsByImage.class.cast(context).findElementByImage(getLocatorString());531 }532 if (FindsByFluentSelector.class.isAssignableFrom(contextClass)) {533 return super.findElement(context);534 }535 throw formIllegalArgumentException(contextClass, FindsByImage.class, FindsByFluentSelector.class);536 }537 @Override public String toString() {538 return "By.Image: " + getLocatorString();539 }540 }541 public static class ByCustom extends MobileBy implements Serializable {542 protected ByCustom(String selector) {543 super(MobileSelector.CUSTOM, selector);544 }545 /**546 * {@inheritDoc}547 *548 * @throws WebDriverException when current session doesn't support the given selector or when549 * value of the selector is not consistent.550 * @throws IllegalArgumentException when it is impossible to find something on the given551 * {@link SearchContext} instance552 */553 @SuppressWarnings("unchecked")554 @Override public List<WebElement> findElements(SearchContext context) {555 Class<?> contextClass = context.getClass();556 if (FindsByCustom.class.isAssignableFrom(contextClass)) {557 return FindsByCustom.class.cast(context).findElementsByCustom(getLocatorString());558 }559 if (FindsByFluentSelector.class.isAssignableFrom(contextClass)) {560 return super.findElements(context);561 }562 throw formIllegalArgumentException(contextClass, FindsByCustom.class, FindsByFluentSelector.class);563 }564 /**565 * {@inheritDoc}566 *567 * @throws WebDriverException when current session doesn't support the given selector or when568 * value of the selector is not consistent.569 * @throws IllegalArgumentException when it is impossible to find something on the given570 * {@link SearchContext} instance571 */572 @Override public WebElement findElement(SearchContext context) {573 Class<?> contextClass = context.getClass();574 if (FindsByCustom.class.isAssignableFrom(contextClass)) {575 return FindsByCustom.class.cast(context).findElementByCustom(getLocatorString());576 }577 if (FindsByFluentSelector.class.isAssignableFrom(contextClass)) {578 return super.findElement(context);579 }580 throw formIllegalArgumentException(contextClass, FindsByCustom.class, FindsByFluentSelector.class);581 }582 @Override public String toString() {583 return "By.Custom: " + getLocatorString();584 }585 }586 public static class ByAndroidViewTag extends MobileBy implements Serializable {587 public ByAndroidViewTag(String tag) {588 super(MobileSelector.ANDROID_VIEWTAG, tag);589 }590 /**591 * {@inheritDoc}592 *593 * @throws WebDriverException when current session doesn't support the given selector or when594 * value of the selector is not consistent.595 * @throws IllegalArgumentException when it is impossible to find something on the given596 * {@link SearchContext} instance597 */598 @SuppressWarnings("unchecked")599 @Override600 public List<WebElement> findElements(SearchContext context) throws WebDriverException,601 IllegalArgumentException {602 Class<?> contextClass = context.getClass();603 if (FindsByAndroidViewTag.class.isAssignableFrom(contextClass)) {604 return FindsByAndroidViewTag.class.cast(context)605 .findElementsByAndroidViewTag(getLocatorString());606 }607 if (FindsByFluentSelector.class.isAssignableFrom(contextClass)) {608 return super.findElements(context);609 }610 throw formIllegalArgumentException(contextClass, FindsByAndroidViewTag.class,611 FindsByFluentSelector.class);612 }613 /**614 * {@inheritDoc}615 *616 * @throws WebDriverException when current session doesn't support the given selector or when617 * value of the selector is not consistent.618 * @throws IllegalArgumentException when it is impossible to find something on the given619 * {@link SearchContext} instance620 */621 @Override public WebElement findElement(SearchContext context) throws WebDriverException,622 IllegalArgumentException {623 Class<?> contextClass = context.getClass();624 if (FindsByAndroidViewTag.class.isAssignableFrom(contextClass)) {625 return FindsByAndroidViewTag.class.cast(context)626 .findElementByAndroidViewTag(getLocatorString());627 }628 if (FindsByFluentSelector.class.isAssignableFrom(contextClass)) {629 return super.findElement(context);630 }631 throw formIllegalArgumentException(contextClass, FindsByAndroidViewTag.class,632 FindsByFluentSelector.class);633 }634 @Override public String toString() {635 return "By.AndroidViewTag: " + getLocatorString();636 }637 }638}...
By.java
Source:By.java
1// Licensed to the Software Freedom Conservancy (SFC) under one2// or more contributor license agreements. See the NOTICE file3// distributed with this work for additional information4// regarding copyright ownership. The SFC licenses this file5// to you under the Apache License, Version 2.0 (the6// "License"); you may not use this file except in compliance7// with the License. You may obtain a copy of the License at8//9// http://www.apache.org/licenses/LICENSE-2.010//11// Unless required by applicable law or agreed to in writing,12// software distributed under the License is distributed on an13// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY14// KIND, either express or implied. See the License for the15// specific language governing permissions and limitations16// under the License.17package com.testpros.fast;18import io.appium.java_client.MobileSelector;19/**20 * Mechanism used to locate elements within a document. In order to create your own locating21 * mechanisms, it is possible to subclass this class and override the protected methods as required,22 * though it is expected that all subclasses rely on the basic finding mechanisms provided23 * through static methods of this class:24 *25 * <code>26 * public WebElement findElement(WebDriver driver) {27 * WebElement element = driver.findElement(By.id(getSelector()));28 * if (element == null)29 * element = driver.findElement(By.name(getSelector());30 * return element;31 * }32 * </code>33 */34//public class By extends io.appium.java_client.MobileBy {35//public abstract class By extends org.openqa.selenium.By {36public class By {37 org.openqa.selenium.By by;38 public By(org.openqa.selenium.By by) {39 this.by = by;40 }41 public org.openqa.selenium.By getBy() {42 return by;43 }44 45 /**46 * @param id The value of the "id" attribute to search for.47 * @return A By which locates elements by the value of the "id" attribute.48 */49 public static By id(String id) {50 return new By(org.openqa.selenium.By.id(id));51 }52 /**53 * @param linkText The exact text to match against.54 * @return A By which locates A elements by the exact text it displays.55 */56 public static By linkText(String linkText) {57 return new By(org.openqa.selenium.By.linkText(linkText));58 }59 /**60 * @param partialLinkText The partial text to match against61 * @return a By which locates elements that contain the given link text.62 */63 public static By partialLinkText(String partialLinkText) {64 return new By(org.openqa.selenium.By.partialLinkText(partialLinkText));65 }66 /**67 * @param name The value of the "name" attribute to search for.68 * @return A By which locates elements by the value of the "name" attribute.69 */70 public static By name(String name) {71 return new By(org.openqa.selenium.By.name(name));72 }73 /**74 * @param tagName The element's tag name.75 * @return A By which locates elements by their tag name.76 */77 public static By tagName(String tagName) {78 return new By(org.openqa.selenium.By.tagName(tagName));79 }80 /**81 * @param xpathExpression The XPath to use.82 * @return A By which locates elements via XPath.83 */84 public static By xpath(String xpathExpression) {85 return new By(org.openqa.selenium.By.xpath(xpathExpression));86 }87 /**88 * Find elements based on the value of the "class" attribute. If an element has multiple classes, then89 * this will match against each of them. For example, if the value is "one two onone", then the90 * class names "one" and "two" will match.91 *92 * @param className The value of the "class" attribute to search for.93 * @return A By which locates elements by the value of the "class" attribute.94 */95 public static By className(String className) {96 return new By(org.openqa.selenium.By.className(className));97 }98 /**99 * Find elements via the driver's underlying W3C Selector engine. If the browser does not100 * implement the Selector API, a best effort is made to emulate the API. In this case, we strive101 * for at least CSS2 support, but offer no guarantees.102 *103 * @param cssSelector CSS expression.104 * @return A By which locates elements by CSS.105 */106 public static By cssSelector(String cssSelector) {107 return new By(org.openqa.selenium.By.cssSelector(cssSelector));108 }109 /**110 * Read http://developer.android.com/intl/ru/tools/testing-support-library/111 * index.html#uia-apis112 *113 * @param uiautomatorText is Android UIAutomator string114 * @return an instance of {@link By.ByAndroidUIAutomator}115 */116 public static By AndroidUIAutomator(final String uiautomatorText) {117 return new By(io.appium.java_client.MobileBy.AndroidUIAutomator(uiautomatorText));118 }119 /**120 * About Android accessibility121 * https://developer.android.com/intl/ru/training/accessibility/accessible-app.html122 * About iOS accessibility123 * https://developer.apple.com/library/ios/documentation/UIKit/Reference/124 * UIAccessibilityIdentification_Protocol/index.html125 *126 * @param accessibilityId id is a convenient UI automation accessibility Id.127 * @return an instance of {@link By.ByAndroidUIAutomator}128 */129 public static By AccessibilityId(final String accessibilityId) {130 return new By(io.appium.java_client.MobileBy.AccessibilityId(accessibilityId));131 }132 /**133 * This locator strategy is available in XCUITest Driver mode.134 *135 * @param iOSClassChainString is a valid class chain locator string.136 * See <a href="https://github.com/facebook/WebDriverAgent/wiki/Queries">137 * the documentation</a> for more details138 * @return an instance of {@link By.ByIosClassChain}139 */140 public static By iOSClassChain(final String iOSClassChainString) {141 return new By(io.appium.java_client.MobileBy.iOSClassChain(iOSClassChainString));142 }143 /**144 * This locator strategy is only available in Espresso Driver mode.145 *146 * @param dataMatcherString is a valid class chain locator string.147 * See <a href="https://github.com/appium/appium-espresso-driver/pull/386">148 * the documentation</a> for more details149 * @return an instance of {@link By.ByAndroidDataMatcher}150 */151 public static By androidDataMatcher(final String dataMatcherString) {152 return new By(io.appium.java_client.MobileBy.androidDataMatcher(dataMatcherString));153 }154 /**155 * This locator strategy is available in XCUITest Driver mode.156 *157 * @param iOSNsPredicateString is an an iOS NsPredicate String158 * @return an instance of {@link By.ByIosNsPredicate}159 */160 public static By iOSNsPredicateString(final String iOSNsPredicateString) {161 return new By(io.appium.java_client.MobileBy.iOSNsPredicateString(iOSNsPredicateString));162 }163 public static By windowsAutomation(final String windowsAutomation) {164 return new By(io.appium.java_client.MobileBy.windowsAutomation(windowsAutomation));165 }166 /**167 * This locator strategy is available in Espresso Driver mode.168 *169 * @param tag is an view tag string170 * @return an instance of {@link ByAndroidViewTag}171 * @since Appium 1.8.2 beta172 */173 public static By AndroidViewTag(final String tag) {174 return new By(io.appium.java_client.MobileBy.AndroidViewTag(tag));175 }176 /**177 * This locator strategy is available only if OpenCV libraries and178 * NodeJS bindings are installed on the server machine.179 *180 * @param b64Template base64-encoded template image string. Supported image formats are the same181 * as for OpenCV library.182 * @return an instance of {@link ByImage}183 * @see <a href="https://github.com/appium/appium/blob/master/docs/en/writing-running-appium/image-comparison.md">184 * The documentation on Image Comparison Features</a>185 * @see <a href="https://github.com/appium/appium-base-driver/blob/master/lib/basedriver/device-settings.js">186 * The settings available for lookup fine-tuning</a>187 * @since Appium 1.8.2188 */189 public static By image(final String b64Template) {190 return new By(io.appium.java_client.MobileBy.image(b64Template));191 }192 /**193 * This type of locator requires the use of the 'customFindModules' capability and a194 * separately-installed element finding plugin.195 *196 * @param selector selector to pass to the custom element finding plugin197 * @return an instance of {@link ByCustom}198 * @since Appium 1.9.2199 */200 public static By custom(final String selector) {201 return new By(io.appium.java_client.MobileBy.custom(selector));202 }203}...
ByParserTest.java
Source:ByParserTest.java
1/*2 * MIT License3 *4 * Copyright (c) 2018 Excelium5 *6 * Permission is hereby granted, free of charge, to any person obtaining a copy7 * of this software and associated documentation files (the "Software"), to deal8 * in the Software without restriction, including without limitation the rights9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell10 * copies of the Software, and to permit persons to whom the Software is11 * furnished to do so, subject to the following conditions:12 *13 * The above copyright notice and this permission notice shall be included in all14 * copies or substantial portions of the Software.15 *16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE22 * SOFTWARE.23 */24package excelium.core.by;25import excelium.core.driver.ContextAwareWebDriver;26import io.appium.java_client.MobileBy;27import mockit.Expectations;28import mockit.Mocked;29import org.junit.Assert;30import org.junit.Test;31import org.openqa.selenium.By;32import org.openqa.selenium.support.ByIdOrName;33/**34 * Tests for {@link ByParser}.35 *36 * @author PhungDucKien37 * @since 2018.05.1638 */39public class ByParserTest {40 @Mocked41 private ContextAwareWebDriver webDriver;42 @Test43 public void testParseByWeb() {44 new Expectations() {{45 webDriver.isWebContext(); result = true;46 }};47 By by = ByParser.parseBy("id=id", webDriver);48 Assert.assertTrue(by instanceof By.ById);49 Assert.assertEquals("By.id: id", by.toString());50 by = ByParser.parseBy("link=link", webDriver);51 Assert.assertTrue(by instanceof By.ByLinkText);52 Assert.assertEquals("By.linkText: link", by.toString());53 by = ByParser.parseBy("partial link=link", webDriver);54 Assert.assertTrue(by instanceof By.ByPartialLinkText);55 Assert.assertEquals("By.partialLinkText: link", by.toString());56 by = ByParser.parseBy("tag=button", webDriver);57 Assert.assertTrue(by instanceof By.ByTagName);58 Assert.assertEquals("By.tagName: button", by.toString());59 by = ByParser.parseBy("name=name", webDriver);60 Assert.assertTrue(by instanceof By.ByName);61 Assert.assertEquals("By.name: name", by.toString());62 by = ByParser.parseBy("class=class", webDriver);63 Assert.assertTrue(by instanceof By.ByClassName);64 Assert.assertEquals("By.className: class", by.toString());65 by = ByParser.parseBy("css=css", webDriver);66 Assert.assertTrue(by instanceof ByCss);67 Assert.assertEquals("By.css: css", by.toString());68 by = ByParser.parseBy("xpath=//xpath", webDriver);69 Assert.assertTrue(by instanceof By.ByXPath);70 Assert.assertEquals("By.xpath: //xpath", by.toString());71 by = ByParser.parseBy("identifier=identifier", webDriver);72 Assert.assertTrue(by instanceof ByIdOrName);73 Assert.assertEquals("by id or name \"identifier\"", by.toString());74 by = ByParser.parseBy("alt=alt", webDriver);75 Assert.assertTrue(by instanceof ByAlt);76 Assert.assertEquals("By.alt: alt", by.toString());77 by = ByParser.parseBy("dom=dom", webDriver);78 Assert.assertTrue(by instanceof ByDom);79 Assert.assertEquals("By.dom: dom", by.toString());80 by = ByParser.parseBy("index=1", webDriver);81 Assert.assertTrue(by instanceof ByIndex);82 Assert.assertEquals("By.index: [null][1]", by.toString());83 by = ByParser.parseBy("variable=variable", webDriver);84 Assert.assertTrue(by instanceof ByVariable);85 Assert.assertEquals("By.variable: variable", by.toString());86 by = ByParser.parseBy("//xpath", webDriver);87 Assert.assertTrue(by instanceof By.ByXPath);88 Assert.assertEquals("By.xpath: //xpath", by.toString());89 by = ByParser.parseBy("document.getElementById('login-btn')", webDriver);90 Assert.assertTrue(by instanceof ByDom);91 Assert.assertEquals("By.dom: document.getElementById('login-btn')", by.toString());92 by = ByParser.parseBy("identifier", webDriver);93 Assert.assertTrue(by instanceof ByIdOrName);94 Assert.assertEquals("by id or name \"identifier\"", by.toString());95 }96 @Test97 public void testParseByMobile() {98 new Expectations() {{99 webDriver.isWebContext(); result = false;100 }};101 By by = ByParser.parseBy("accessibility id=accessibility id", webDriver);102 Assert.assertTrue(by instanceof MobileBy.ByAccessibilityId);103 Assert.assertEquals("By.AccessibilityId: accessibility id", by.toString());104 by = ByParser.parseBy("class=class", webDriver);105 Assert.assertTrue(by instanceof MobileBy.ByClassName);106 Assert.assertEquals("By.className: class", by.toString());107 by = ByParser.parseBy("id=id", webDriver);108 Assert.assertTrue(by instanceof MobileBy.ById);109 Assert.assertEquals("By.id: id", by.toString());110 by = ByParser.parseBy("name=name", webDriver);111 Assert.assertTrue(by instanceof MobileBy.ByName);112 Assert.assertEquals("By.name: name", by.toString());113 by = ByParser.parseBy("xpath=//xpath", webDriver);114 Assert.assertTrue(by instanceof MobileBy.ByXPath);115 Assert.assertEquals("By.xpath: //xpath", by.toString());116 by = ByParser.parseBy("android uiautomator=android uiautomator", webDriver);117 Assert.assertTrue(by instanceof MobileBy.ByAndroidUIAutomator);118 Assert.assertEquals("By.AndroidUIAutomator: android uiautomator", by.toString());119 by = ByParser.parseBy("android viewtag=android viewtag", webDriver);120 Assert.assertTrue(by instanceof MobileBy.ByAndroidViewTag);121 Assert.assertEquals("By.AndroidViewTag: android viewtag", by.toString());122 by = ByParser.parseBy("android datamatcher=android datamatcher", webDriver);123 Assert.assertTrue(by instanceof MobileBy.ByAndroidDataMatcher);124 Assert.assertEquals("By.FindsByAndroidDataMatcher: android datamatcher", by.toString());125 by = ByParser.parseBy("ios predicate string=ios predicate string", webDriver);126 Assert.assertTrue(by instanceof MobileBy.ByIosNsPredicate);127 Assert.assertEquals("By.IosNsPredicate: ios predicate string", by.toString());128 by = ByParser.parseBy("ios class chain=ios class chain", webDriver);129 Assert.assertTrue(by instanceof MobileBy.ByIosClassChain);130 Assert.assertEquals("By.IosClassChain: ios class chain", by.toString());131 by = ByParser.parseBy("windows uiautomation=windows uiautomation", webDriver);132 Assert.assertTrue(by instanceof MobileBy.ByWindowsAutomation);133 by = ByParser.parseBy("index=1", webDriver);134 Assert.assertTrue(by instanceof ByIndex);135 Assert.assertEquals("By.index: [null][1]", by.toString());136 by = ByParser.parseBy("variable=variable", webDriver);137 Assert.assertTrue(by instanceof ByVariable);138 Assert.assertEquals("By.variable: variable", by.toString());139 by = ByParser.parseBy("//xpath", webDriver);140 Assert.assertTrue(by instanceof MobileBy.ByXPath);141 Assert.assertEquals("By.xpath: //xpath", by.toString());142 by = ByParser.parseBy("accessibility id", webDriver);143 Assert.assertTrue(by instanceof MobileBy.ByAccessibilityId);144 Assert.assertEquals("By.AccessibilityId: accessibility id", by.toString());145 }146}...
AndroidLocatorConverter.java
Source:AndroidLocatorConverter.java
1package com.github.mishaninss.arma.uidriver.android;2import com.github.mishaninss.arma.uidriver.webdriver.LocatorConverter;3import io.appium.java_client.MobileBy;4import org.openqa.selenium.By;5import org.springframework.context.annotation.Profile;6import org.springframework.stereotype.Component;7/**8 * @author Sergey Mishanin Class for locators handling.9 */10@Component11@Profile("android")12public final class AndroidLocatorConverter extends LocatorConverter {13 public static final String LOCATOR_TYPE_ANDROID_UI_AUTOMATOR = "androiduiautomator";14 public static final String LOCATOR_TYPE_ANDROID_VIEW_TAG = "androidviewtag";15 public static final String LOCATOR_ACCESSIBILITY_ID = "accessibilityid";16 public AndroidLocatorConverter() {17 addConverter(LOCATOR_TYPE_ANDROID_UI_AUTOMATOR, this::byAndroidUiAutomator);18 addConverter(LOCATOR_TYPE_ANDROID_VIEW_TAG, this::byAndroidViewTag);19 addConverter(LOCATOR_ACCESSIBILITY_ID, this::byAccessibilityId);20 }21 /**22 * Converter for type "androidUiAutomator"23 */24 public By byAndroidUiAutomator(final String locator) {25 return MobileBy.AndroidUIAutomator(locator);26 }27 /**28 * Converter for type "androidViewTag"29 */30 public By byAndroidViewTag(final String locator) {31 return MobileBy.AndroidViewTag(locator);32 }33 /**34 * Converter for type "accessibilityId"35 */36 public By byAccessibilityId(final String locator) {37 return MobileBy.AccessibilityId(locator);38 }39}...
MobileBy.ByAndroidViewTag
Using AI Code Generation
1MobileElement element = driver.findElement(MobileBy.ByAndroidViewTag("android:id/text1"));2MobileElement element = driver.findElement(MobileBy.ByAndroidViewTag("android:id/text1"));3MobileElement element = driver.findElement(MobileBy.ByAndroidViewTag("android:id/text1"));4MobileElement element = driver.findElement(MobileBy.ByAndroidViewTag("android:id/text1"));5MobileElement element = driver.findElement(MobileBy.ByAndroidViewTag("android:id/text1"));6MobileElement element = driver.findElement(MobileBy.ByAndroidViewTag("android:id/text1"));7MobileElement element = driver.findElement(MobileBy.ByAndroidViewTag("android:id/text1"));8MobileElement element = driver.findElement(MobileBy.ByAndroidViewTag("android:id/text1"));9MobileElement element = driver.findElement(MobileBy.ByAndroidViewTag("android:id/text1"));10MobileElement element = driver.findElement(MobileBy.ByAndroidViewTag("android:id/text1"));11MobileElement element = driver.findElement(MobileBy.ByAndroidViewTag("android:id/text1"));12MobileElement element = driver.findElement(MobileBy.ByAndroidViewTag("android:id/text1"));
MobileBy.ByAndroidViewTag
Using AI Code Generation
1MobileElement element = driver.findElement(MobileBy.ByAndroidViewTag("android:id/text1"));2MobileElement element = driver.findElement(MobileBy.ByAndroidViewTag("android:id/text1"));3MobileElement element = driver.findElement(MobileBy.ByIosUIAutomation(".elements()[0]"));4MobileElement element = driver.findElement(MobileBy.ByIosUIAutomation(".elements()[0]"));5MobileElement element = driver.findElement(MobileBy.ByIosNsPredicate("value == 'test'"));6MobileElement element = driver.findElement(MobileBy.ByIosNsPredicate("value == 'test'"));7MobileElement element = driver.findElement(MobileBy.ByIosClassChain("**/XCUIElementTypeCell[1]"));8MobileElement element = driver.findElement(MobileBy.ByIosClassChain("**/XCUIElementTypeCell[1]"));9MobileElement element = driver.findElement(MobileBy.ByIosPredicate("label == 'test'"));10MobileElement element = driver.findElement(MobileBy.ByIosPredicate("label == 'test'"));11MobileElement element = driver.findElement(MobileBy.ByAccessibilityId("test"));12MobileElement element = driver.findElement(MobileBy.ByAccessibilityId("test"));
MobileBy.ByAndroidViewTag
Using AI Code Generation
1MobileElement element = driver.findElementByAndroidViewTag("tag");2MobileElement element = driver.findElement(MobileBy.ByAndroidViewTag("tag"));3List<MobileElement> element = driver.findElementsByAndroidViewTag("tag");4List<MobileElement> element = driver.findElements(MobileBy.ByAndroidViewTag("tag"));5MobileElement element = driver.findElementByAndroidViewTag("tag", "value");6MobileElement element = driver.findElement(MobileBy.ByAndroidViewTag("tag", "value"));7List<MobileElement> element = driver.findElementsByAndroidViewTag("tag", "value");8List<MobileElement> element = driver.findElements(MobileBy.ByAndroidViewTag("tag", "value"));9MobileElement element = driver.findElementByAndroidViewTag("tag", "value", "index");10MobileElement element = driver.findElement(MobileBy.ByAndroidViewTag("tag", "value", "index"));11List<MobileElement> element = driver.findElementsByAndroidViewTag("tag", "value", "index");12List<MobileElement> element = driver.findElements(MobileBy.ByAndroidViewTag("tag", "value", "index"));
MobileBy.ByAndroidViewTag
Using AI Code Generation
1MobileBy.ByAndroidViewTag viewTag = new MobileBy.ByAndroidViewTag("some tag");2MobileBy.ByAndroidViewTag viewTag = MobileBy.AndroidViewTag("some tag");3MobileBy.ByAndroidViewTag viewTag = MobileBy.AndroidViewTag("some tag");4MobileBy.ByAndroidViewTag viewTag = new MobileBy.ByAndroidViewTag("some tag");5MobileBy.ByAndroidViewTag viewTag = MobileBy.AndroidViewTag("some tag");6MobileBy.ByAndroidViewTag viewTag = MobileBy.AndroidViewTag("some tag");7MobileBy.ByAndroidViewTag viewTag = new MobileBy.ByAndroidViewTag("some tag");8MobileBy.ByAndroidViewTag viewTag = MobileBy.AndroidViewTag("some tag");9MobileBy.ByAndroidViewTag viewTag = MobileBy.AndroidViewTag("some tag");10MobileBy.ByAndroidViewTag viewTag = new MobileBy.ByAndroidViewTag("some tag");11MobileBy.ByAndroidViewTag viewTag = MobileBy.AndroidViewTag("some tag");12MobileBy.ByAndroidViewTag viewTag = MobileBy.AndroidViewTag("some tag");13MobileBy.ByAndroidViewTag viewTag = new MobileBy.ByAndroidViewTag("some
MobileBy.ByAndroidViewTag
Using AI Code Generation
1MobileElement element = (MobileElement) driver.findElement(MobileBy.ByAndroidViewTag("android:id/button1"));2element.click();3MobileElement element = (MobileElement) driver.findElement(MobileBy.ByAndroidDataMatcher("new UiSelector().text(\"OK\")"));4element.click();5MobileElement element = (MobileElement) driver.findElement(MobileBy.ByAndroidUIAutomator("new UiSelector().text(\"OK\")"));6element.click();7MobileElement element = (MobileElement) driver.findElement(MobileBy.ByAccessibilityId("OK"));8element.click();9MobileElement element = (MobileElement) driver.findElement(MobileBy.ByIosUIAutomation(".elements()[0]"));10element.click();11MobileElement element = (MobileElement) driver.findElement(MobileBy.ByIosNsPredicate("type == \"XCUIElementTypeButton\" AND name == \"OK\""));12element.click();13MobileElement element = (MobileElement) driver.findElement(MobileBy.ByIosClassChain("**/XCUIElementTypeButton[`name == \"OK\"`"));14element.click();15MobileElement element = (MobileElement) driver.findElement(MobileBy.ByIosUIAutomation(".elements()[0]"));16element.click();17MobileElement element = (MobileElement) driver.findElement(MobileBy.ByIosUIAutomation(".elements()[0]"));18element.click();
MobileBy.ByAndroidViewTag
Using AI Code Generation
1MobileBy.ByAndroidViewTag("android.widget.TextView").findElement(driver);2MobileBy.ByAndroidViewTag("android.widget.TextView").findElements(driver);3MobileBy.ByAndroidViewTag("android.widget.TextView").findElement(driver);4MobileBy.ByAndroidViewTag("android.widget.TextView").findElements(driver);5MobileBy.ByAndroidViewTag("android.widget.TextView").findElement(driver);6MobileBy.ByAndroidViewTag("android.widget.TextView").findElements(driver);7MobileBy.ByAndroidViewTag("android.widget.TextView").findElement(driver);8MobileBy.ByAndroidViewTag("android.widget.TextView").findElements(driver);9MobileBy.ByAndroidViewTag("android.widget.TextView").findElement(driver);10MobileBy.ByAndroidViewTag("android.widget.TextView").findElements(driver);11MobileBy.ByAndroidViewTag("android.widget.TextView").findElement(driver);12MobileBy.ByAndroidViewTag("android.widget.TextView").findElements(driver);13MobileBy.ByAndroidViewTag("android.widget.TextView").findElement(driver);14MobileBy.ByAndroidViewTag("android.widget.TextView").findElements(driver
MobileBy.ByAndroidViewTag
Using AI Code Generation
1import io.appium.java_client.MobileBy;2import org.openqa.selenium.By;3By locator = MobileBy.AndroidViewTag("android.widget.TextView");4import io.appium.java_client.MobileBy;5import org.openqa.selenium.By;6By locator = MobileBy.IosUIAutomation(".elements().withName(\"TextField1\")");7import io.appium.java_client.MobileBy;8import org.openqa.selenium.By;9By locator = MobileBy.IosNsPredicate("name == 'TextField1'");10locator = Appium::Mobile::By::AndroidViewTag.new("android.widget.TextView")11locator = Appium::Mobile::By::IosUIAutomation.new(".elements().withName(\"TextField1\")")12locator = Appium::Mobile::By::IosNsPredicate.new("name == 'TextField1'")13locator = Appium::Core::By::AndroidViewTag.new("android.widget.TextView")14locator = Appium::Core::By::IosUIAutomation.new(".elements().withName(\"TextField1\")")15locator = Appium::Core::By::IosNsPredicate.new("name == 'TextField1'")16import { MobileBy } from 'appium';17const locator = MobileBy.AndroidViewTag("android.widget.TextView");
MobileBy.ByAndroidViewTag
Using AI Code Generation
1MobileElement element = (MobileElement) driver.findElement(MobileBy.ByAndroidViewTag.tagName("android.widget.TextView").text("Text"));2MobileElement element = (MobileElement) driver.findElement(MobileBy.ByAndroidViewTag.tagName("android.widget.TextView").text("Text"));3MobileElement element = (MobileElement) driver.findElement(MobileBy.ByAndroidViewTag.tagName("android.widget.TextView").text("Text"));4MobileElement element = (MobileElement) driver.findElement(MobileBy.ByAndroidViewTag.tagName("android.widget.TextView").text("Text"));5MobileElement element = (MobileElement) driver.findElement(MobileBy.ByAndroidViewTag.tagName("android.widget.TextView").text("Text"));6MobileElement element = (MobileElement) driver.findElement(MobileBy.ByAndroidViewTag
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!