How to use MobileBy.ByAndroidViewMatcher class of io.appium.java_client package

Best io.appium code snippet using io.appium.java_client.MobileBy.ByAndroidViewMatcher

MobileBy.java

Source:MobileBy.java Github

copy

Full Screen

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}...

Full Screen

Full Screen

MobileBy.ByAndroidViewMatcher

Using AI Code Generation

copy

Full Screen

1WebElement view = driver.findElement(matcher);2view.click();3MobileBy.ByAndroidUIAutomator uiautomator = new MobileBy.ByAndroidUIAutomator("new UiSelector().text(\"View\")");4WebElement view = driver.findElement(uiautomator);5view.click();6MobileBy.ByIosUIAutomation iosuiautomation = new MobileBy.ByIosUIAutomation(".elemen

Full Screen

Full Screen

MobileBy.ByAndroidViewMatcher

Using AI Code Generation

copy

Full Screen

1MobileBy.ByAndroidViewMatcher androidViewMatcher = new MobileBy.ByAndroidViewMatcher("new UiSelector().description(\"Some description\")");2MobileElement element = (MobileElement) driver.findElement(androidViewMatcher);3System.out.println(element.getText());4MobileBy.ByAndroidUIAutomator androidUIAutomator = new MobileBy.ByAndroidUIAutomator("new UiSelector().description(\"Some description\")");5MobileElement element = (MobileElement) driver.findElement(androidUIAutomator);6System.out.println(element.getText());7MobileBy.ByIosUIAutomation iosUIAutomation = new MobileBy.ByIosUIAutomation(".elements()[0].cells()[0].staticTexts()[0]");8MobileElement element = (MobileElement) driver.findElement(iosUIAutomation);9System.out.println(element.getText());10MobileBy.ByAccessibilityId accessibilityId = new MobileBy.ByAccessibilityId("Some description");11MobileElement element = (MobileElement) driver.findElement(accessibilityId);12System.out.println(element.getText());13MobileBy.AndroidUIAutomator androidUIAutomator = MobileBy.AndroidUIAutomator("new UiSelector().description(\"Some description\")");14MobileElement element = (MobileElement) driver.findElement(androidUIAutomator);15System.out.println(element.getText());16MobileBy.IosUIAutomation iosUIAutomation = MobileBy.IosUIAutomation(".elements()[0].cells()[0].staticTexts()[0]");17MobileElement element = (MobileElement) driver.findElement(iosUIAutomation);18System.out.println(element.getText());19MobileBy.AccessibilityId accessibilityId = MobileBy.AccessibilityId("Some description");20MobileElement element = (MobileElement) driver.findElement(accessibilityId);21System.out.println(element.getText());22MobileBy.AndroidDataMatcher androidDataMatcher = MobileBy.AndroidDataMatcher("name", "value");23MobileElement element = (MobileElement) driver.findElement(androidDataMatcher);

Full Screen

Full Screen

MobileBy.ByAndroidViewMatcher

Using AI Code Generation

copy

Full Screen

1import io.appium.java_client.MobileBy;2import org.openqa.selenium.By;3By by = MobileBy.AndroidViewMatcher("new UiSelector().text(\"Hello\")");4from appium.webdriver.common.mobileby import MobileBy5from selenium.webdriver.common.by import By6by = MobileBy.AndroidViewMatcher("new UiSelector().text(\"Hello\")")7by = MobileBy::ByAndroidViewMatcher("new UiSelector().text(\"Hello\")")8const { MobileBy } = require('appium-support');9const { By } = require('selenium-webdriver');10const by = MobileBy.AndroidViewMatcher("new UiSelector().text(\"Hello\")");11MobileBy = require('appium-support').MobileBy12By = require('selenium-webdriver').By13by = MobileBy.AndroidViewMatcher("new UiSelector().text(\"Hello\")")14import AppiumSwiftClient15let by = MobileBy.ByAndroidViewMatcher("new UiSelector().text(\"Hello\")")16using OpenQA.Selenium.Appium.Android;17By by = MobileBy.AndroidViewMatcher("new UiSelector().text(\"Hello\")");18import (19func main() {20 by := MobileBy.ByAndroidViewMatcher("new UiSelector().text(\"Hello\")")21 fmt.Println(by)22}

Full Screen

Full Screen

MobileBy.ByAndroidViewMatcher

Using AI Code Generation

copy

Full Screen

1MobileElement element = (MobileElement) driver.findElement(MobileBy.ByAndroidViewMatcher2 .androidViewMatcher(withClassName(Matchers.equalTo("android.widget.TextView"))3 .description("Text")));4element.click();5var element = driver.findElement(MobileBy.ByAndroidViewMatcher6 .androidViewMatcher(withClassName(equalTo("android.widget.TextView"))7 .description("Text")));8element.click();9element = driver.find_element(MobileBy.ByAndroidViewMatcher10 .androidViewMatcher(withClassName(equalTo("android.widget.TextView"))11 .description("Text")))12element.click()13element = driver.find_element(MobileBy.ByAndroidViewMatcher14 .androidViewMatcher(withClassName(equalTo("android.widget.TextView"))15 .description("Text")))16element.click()17$element = $driver->findElement(MobileBy::ByAndroidViewMatcher18 ->androidViewMatcher(withClassName(equalTo("android.widget.TextView"))19 ->description("Text")));20$element->click();21element = driver.findElement(MobileBy.ByAndroidViewMatcher22 .androidViewMatcher(withClassName(equalTo("android.widget.TextView"))23 .description("Text")))24element.click()25element = driver.findElement(MobileBy.ByAndroidViewMatcher26 .androidViewMatcher(withClassName(equalTo("android.widget.TextView"))27 .description("Text")))28element.click()29var element = driver.FindElement(MobileBy.ByAndroidViewMatcher30 .androidViewMatcher(withClassName(equalTo("android.widget.TextView"))31 .description("Text")));32element.Click();

Full Screen

Full Screen

MobileBy.ByAndroidViewMatcher

Using AI Code Generation

copy

Full Screen

1MobileElement myElement = (MobileElement) driver.findElementByAndroidViewMatcher("new UiSelector().description(\"MyElement\")");2my_element = @driver.find_element(:android_view_matcher, "new UiSelector().description(\"MyElement\")")3var myElement = driver.findElement(MobileBy.AndroidViewMatcher("new UiSelector().description(\"MyElement\")"));4var myElement = driver.findElement(MobileBy.AndroidViewMatcher("new UiSelector().description(\"MyElement\")"));5var myElement = driver.findElement(MobileBy.AndroidViewMatcher("new UiSelector().description(\"MyElement\")"));6var myElement = driver.findElement(MobileBy.AndroidViewMatcher("new UiSelector().description(\"MyElement\")"));7var myElement = driver.findElement(MobileBy.AndroidViewMatcher("new UiSelector().description(\"MyElement\")"));8var myElement = driver.findElement(MobileBy.AndroidViewMatcher("new UiSelector().description(\"MyElement\")"));9var myElement = driver.findElement(MobileBy.AndroidViewMatcher("new UiSelector().description(\"MyElement\")"));10var myElement = driver.findElement(MobileBy.AndroidViewMatcher("new UiSelector().description(\"MyElement\")"));11var myElement = driver.findElement(MobileBy.AndroidViewMatcher("

Full Screen

Full Screen

MobileBy.ByAndroidViewMatcher

Using AI Code Generation

copy

Full Screen

1import java.net.MalformedURLException;2import java.net.URL;3import java.util.concurrent.TimeUnit;4import org.openqa.selenium.By;5import org.openqa.selenium.remote.DesiredCapabilities;6import io.appium.java_client.MobileBy;7import io.appium.java_client.android.AndroidDriver;8import io.appium.java_client.remote.MobileCapabilityType;9public class FindElementByAndroidViewMatcher {10public static void main(String[] args) throws MalformedURLException {11DesiredCapabilities caps = new DesiredCapabilities();12caps.setCapability(MobileCapabilityType.DEVICE_NAME, "Pixel_3_API_30_x86");13caps.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");14caps.setCapability(MobileCapabilityType.PLATFORM_VERSION, "11.0");15caps.setCapability(MobileCapabilityType.UDID, "emulator-5554");16caps.setCapability(MobileCapabilityType.NEW_COMMAND_TIMEOUT, 14);17caps.setCapability("appPackage", "com.androidsample.generalstore");18caps.setCapability("appActivity", ".SplashActivity");

Full Screen

Full Screen

MobileBy.ByAndroidViewMatcher

Using AI Code Generation

copy

Full Screen

1MobileElement element = driver.findElement(MobileBy.AndroidViewMatcher().withClassName(“android.widget.TextView”));2MobileElement element = driver.findElement(MobileBy.AndroidDataMatcher().withDataMatcher(“text”, “contains”, “Text”));3MobileElement element = driver.findElement(MobileBy.AndroidUIAutomator(“new UiSelector().text(“Text”)”));4MobileElement element = driver.findElement(MobileBy.IosUIAutomation(“new UiSelector().text(“Text”)”));5MobileElement element = driver.findElement(MobileBy.AccessibilityId(“AccessibilityId”));6MobileElement element = driver.findElement(MobileBy.IosClassChain(“**/XCUIElementTypeWindow[1]/XCUIElementTypeOther[2]/XCUIElementTypeOther[1]/XCUIElementTypeOther[1]/XCUIElementTypeOther[1]/XCUIElementTypeOther[1]/XCUIElementTypeOther[1]”));7MobileElement element = driver.findElement(MobileBy.IosNsPredicate(“type == ‘XCUIElementTypeOther’ AND name == ‘Other’”));

Full Screen

Full Screen

MobileBy.ByAndroidViewMatcher

Using AI Code Generation

copy

Full Screen

1package appium;2import java.net.MalformedURLException;3import java.net.URL;4import java.util.concurrent.TimeUnit;5import org.openqa.selenium.By;6import org.openqa.selenium.remote.DesiredCapabilities;7import org.testng.annotations.AfterTest;8import org.testng.annotations.BeforeTest;9import org.testng.annotations.Test;10import io.appium.java_client.MobileBy;11import io.appium.java_client.android.AndroidDriver;12import io.appium.java_client.android.AndroidElement;13public class AppiumJavaClientAndroidViewMatcher {14 AndroidDriver<AndroidElement> driver;15 public void setup() throws MalformedURLException {16 DesiredCapabilities desiredCapabilities = new DesiredCapabilities();17 desiredCapabilities.setCapability("deviceName", "Pixel 3 API 30");18 desiredCapabilities.setCapability("platformName", "Android");19 desiredCapabilities.setCapability("automationName", "UiAutomator2");20 desiredCapabilities.setCapability("appPackage", "com.androidsample.generalstore");21 desiredCapabilities.setCapability("appActivity", ".SplashActivity");22 driver = new AndroidDriver<AndroidElement>(remoteUrl, desiredCapabilities);23 driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);24 }25 public void testAppiumJavaClientAndroidViewMatcher() {26 driver.findElement(MobileBy.AndroidViewMatcher("withText(\"Enter name here\")")).sendKeys("Hello");27 }28 public void teardown() {29 driver.quit();30 }31}32package appium;33import java.net.MalformedURLException;34import java.net.URL;35import java.util.concurrent.TimeUnit;36import org.openqa.selenium.By;37import org.openqa.selenium.remote.DesiredCapabilities;38import org.testng.annotations.AfterTest;39import org.testng.annotations.BeforeTest;40import org.testng.annotations.Test;41import io.appium

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run io.appium automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used methods in MobileBy.ByAndroidViewMatcher

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful