How to use toString method of io.appium.java_client.MobileBy.ByAccessibilityId class

Best io.appium code snippet using io.appium.java_client.MobileBy.ByAccessibilityId.toString

MobileActionLibrary.java

Source:MobileActionLibrary.java Github

copy

Full Screen

...273 }274 return webElement;275 } 276 catch(Exception ex){277 if(ex.getCause().toString().contains("SessionNotFoundException")){278 throw new SessionNotFoundException();279 }280 else if(ex.getCause().toString().contains("UnhandledAlertException")){281 if (AcceptAlert()) {282 return driver.findElement(mobBy);283 }284 if (CommonVariables.TestCaseLog.get() != null) {285 CommonVariables.TestCaseLog.get()286 .info("caught 'UnhandledAlertException' exception while finding '" + mobBy + "' element on '"287 + driver.getTitle() + "' page");288 } else {289 CommonVariables.TestClassLog.get()290 .info("caught 'UnhandledAlertException' exception while finding '" + mobBy + "' element on '"291 + driver.getTitle() + "' page");292 }293 extentLogs.error("Find Element", "caught 'UnhandledAlertException' exception while finding an element on '"294 + driver.getTitle() + "' page");295 throw new UnhandledAlertException(""); 296 }297 else if(ex.getCause().toString().contains("NoSuchElementException")){298 if (AcceptAlert()) {299 return driver.findElement(mobBy);300 }301 if (CommonVariables.TestCaseLog.get() != null) {302 CommonVariables.TestCaseLog.get().info("No such element(" + mobBy + ") found on '"303 + driver.getTitle() + "' page.");304 } else {305 CommonVariables.TestClassLog.get().info("No such element(" + mobBy + ") found on '"306 + driver.getTitle() + "' page at " + driver.getTitle() + "' url.");307 }308 extentLogs.error("Find Element", "No such element éxception found on '"309 + driver.getTitle() + "' page at " + driver.getTitle() + "' url.");310 throw new NoSuchElementException("No such Element");311 }312 else if(ex.getCause().toString().contains("TimeoutException")){313 if (AcceptAlert()) {314 return driver.findElement(mobBy);315 } else {316 if (CommonVariables.TestCaseLog.get() != null) {317 CommonVariables.TestCaseLog.get()318 .info("No such element(" + mobBy + ") found on '" + driver.getTitle() + "' page at "319 + driver.getTitle() + "' url within timelimit (" + timeoutInSeconds + ").");320 } else {321 CommonVariables.TestClassLog.get()322 .info("No such element(" + mobBy + ") found on '" + driver.getTitle() + "' page at "323 + driver.getTitle() + "' url within timelimit (" + timeoutInSeconds + ").");324 }325 extentLogs.error("Find Element", "No such element exception found on '" + driver.getTitle() + "' page at "326 + driver.getTitle() + "' url within timelimit (" + timeoutInSeconds + ").");327 }328 throw new TimeoutException();329 }330 else if(ex.getCause().toString().contains("StaleElementReferenceException")){331 if (CommonVariables.TestCaseLog.get() != null) {332 CommonVariables.TestCaseLog.get()333 .info("Info. Caught 'StaleElementReferenceException' exception while finding (" + mobBy334 + ") element. Class: " + ex.getClass());335 } else {336 CommonVariables.TestClassLog.get()337 .info("Info. Caught 'StaleElementReferenceException' exception while finding (" + mobBy338 + ") element. Class: " + ex.getClass());339 }340 extentLogs.error("Find Element", "Caught 'StaleElementReferenceException' exception while finding an element. Class: " + ex.getClass());341 }342 AcceptAlert();343 try {344 webElement = driver.findElement(mobBy);345 return webElement;346 } catch (Exception e) {347 if (CommonVariables.TestCaseLog.get() != null) {348 CommonVariables.TestCaseLog.get()349 .info("Error. Caught 'StaleElementReferenceException' exception while finding (" + mobBy350 + ") element. Exception Type: " + e.getClass());351 } else {352 CommonVariables.TestClassLog.get()353 .info("Error. Caught 'StaleElementReferenceException' exception while finding (" + mobBy354 + ") element. Exception Type: " + e.getClass());355 }356 throw new StaleElementReferenceException("Stale Exception while finding an element.");357 }358 }359 } 360 /**361 * @author Cigniti362 * @param LocatorType363 * @param LocatorString364 * @param timeoutInSeconds365 * @return366 */367 public WebElement FindElement(MobileLocator LocatorType,String LocatorString, int timeoutInSeconds) {368 WebElement webElement;369 WebDriverWait wait;370 try {371 switch (LocatorType) {372 case ByAccessibilityId:373 if (timeoutInSeconds > 0) {374 wait = new WebDriverWait(driver, timeoutInSeconds);375 webElement = wait.until(ExpectedConditions376 .presenceOfElementLocated(MobileBy377 .AccessibilityId(LocatorString)));378 } else {379 webElement = driver.findElement(MobileBy380 .AccessibilityId(LocatorString));381 extentLogs.pass("MobileLocator", "***** Appium Server strated successfully. *****");382 }383 extentLogs.pass("Find Element", "Successfully find an element using locator type - "+LocatorType+".");384 break;385 case ByXPath:386 if (timeoutInSeconds > 0) {387 wait = new WebDriverWait(driver, timeoutInSeconds);388 webElement = wait.until(ExpectedConditions389 .presenceOfElementLocated(MobileBy390 .xpath(LocatorString)));391 } else {392 webElement = driver.findElement(MobileBy393 .xpath(LocatorString));394 }395 extentLogs.pass("Find Element", "Successfully find an element using locator type - "+LocatorType+".");396 break;397 case ByClassName:398 if (timeoutInSeconds > 0) {399 wait = new WebDriverWait(driver, timeoutInSeconds);400 webElement = wait.until(ExpectedConditions401 .presenceOfElementLocated(MobileBy402 .className(LocatorString)));403 } else {404 webElement = driver.findElement(MobileBy405 .className(LocatorString));406 }407 extentLogs.pass("Find Element", "Successfully find an element using locator type - "+LocatorType+".");408 break;409 case ById:410 if (timeoutInSeconds > 0) {411 wait = new WebDriverWait(driver, timeoutInSeconds);412 webElement = wait.until(ExpectedConditions413 .presenceOfElementLocated(MobileBy414 .id(LocatorString)));415 } else {416 webElement = driver.findElement(MobileBy417 .IosUIAutomation(LocatorString));418 }419 extentLogs.pass("Find Element", "Successfully find an element using locator type - "+LocatorType+".");420 break;421 case AndroidUIAutomator:422 if (timeoutInSeconds > 0) {423 wait = new WebDriverWait(driver, timeoutInSeconds);424 webElement = wait.until(ExpectedConditions425 .presenceOfElementLocated(MobileBy426 .AndroidUIAutomator(LocatorString)));427 } else {428 webElement = driver.findElement(MobileBy429 .IosUIAutomation(LocatorString));430 }431 extentLogs.pass("Find Element", "Successfully find an element using locator type - "+LocatorType+".");432 break;433 case ByName:434 if (timeoutInSeconds > 0) {435 wait = new WebDriverWait(driver, timeoutInSeconds);436 webElement = wait.until(ExpectedConditions437 .presenceOfElementLocated(MobileBy438 .name(LocatorString)));439 } else {440 webElement = driver.findElement(MobileBy441 .name(LocatorString));442 }443 extentLogs.pass("Find Element", "Successfully find an element using locator type - "+LocatorType+".");444 break;445 default:446 return null;447 }448 return webElement;449 } catch (Exception e) {450 return null;451 }452 }453 /**454 * @author Cigniti455 * @param webElement456 * @return457 */458 public boolean ClearInputField(WebElement webElement) {459 try {460 IOSElement mobileWebElement = (IOSElement) webElement;461 mobileWebElement.clear();462 return true;463 } catch (Exception e) {464 return false;465 }466 }467 /**468 * @author Cigniti469 * @param webElement470 * @param value471 * @return472 */473 public boolean type(WebElement webElement, String value) {474 boolean state = false;475 try {476 try {477 webElement.sendKeys(value);478 state = true;479 try { driver.hideKeyboard(); } catch (WebDriverException e1) { } 480 } catch (Exception e) {481 state = false;482 }483 extentLogs.pass("Type", "Successfully entered text value - '"+value+"'.");484 } catch (Exception e) {485 extentLogs.error("Type", "Failed to enter text value - '"+value+"' due to execption - "+e.getMessage()+".");486 e.printStackTrace();487 }488 return state;489 }490 /**491 * @author Cigniti492 * @param webElement493 * @return494 */495 public boolean AndroidTap(WebElement webElement) {496 try {497 AndroidElement elemIOS = (AndroidElement) webElement;498 elemIOS.tap(1, 4);499 extentLogs.pass("Tap", "Successfully tap on an element - "+webElement+".");500 return true;501 } catch (Exception e) {502 extentLogs.error("Tap", "Failed to tap on an element - "+webElement+".");503 e.printStackTrace();504 return false;505 }506 }507 /**508 * @author Cigniti509 * @param webElement510 * @return511 */512 public boolean click(WebElement webElement) {513 boolean state = false;514 try {515 try { driver.hideKeyboard(); } catch (WebDriverException e1) { }516 webElement.click();517 extentLogs.pass("Click", "Successfully clicked.");518 try {519 Thread.sleep(2000);520 state = true;521 } catch (InterruptedException e) {522 extentLogs.error("Click","Element is not clickable.");523 }524 } catch (Exception e) {525 extentLogs.error("Click","Element is not clickable.");526 }527 return state;528 }529 /**530 * @author Cigniti531 * @param objWebElement532 * @param attribute533 * @return534 */535 public String GetElementAttributeValue(WebElement objWebElement,536 String attribute) {537 return objWebElement.getAttribute(attribute);538 }539 /**540 * @author Cigniti541 * @return542 */543 public boolean AcceptAlert() {544 try {545 Alert alert = driver.switchTo().alert();546 alert.accept();547 return true;548 } catch (Exception e) {549 return false;550 }551 }552 /**553 * @author Cigniti554 * @return555 */556 public boolean declineAlert() {557 try {558 Alert alert = driver.switchTo().alert();559 alert.dismiss();560 return true;561 } catch (Exception e) {562 return false;563 }564 }565 /**566 * @author Cigniti567 * @param element568 */569 public void SwipeRight(WebElement element) {570 SwipeElement(element, "right"); 571 }572 /**573 * @author ashsih jain574 * @param element575 */576 public void SwipeBottom(WebElement element) {577 try {578 AndroidElement elemIOS = (AndroidElement) element;579 elemIOS.swipe(SwipeElementDirection.DOWN, 0);580 extentLogs.pass("Swipe", "Successfully Swiped.");581 } catch (Exception e) {582 extentLogs.error("Swipe", "Failed to swipe.");583 e.printStackTrace();584 }585 }586 /**587 * @author Cigniti588 * @param remoteelem589 */590 public void SwipeLeft(WebElement remoteelem) {591 SwipeElement(remoteelem, "left"); 592 }593 /**594 * @author Cigniti595 * @param remoteelem596 * @param direction597 */598 public void SwipeElement(WebElement remoteelem, String direction) {599 Integer pagewidth = driver.manage().window().getSize().width;600 Point eloc = remoteelem.getLocation();601 Integer swipe_startxratio = eloc.getX();602 Integer swipe_endxratio = eloc.getX() + remoteelem.getSize().width;603 Integer yratio =eloc.getY()+(remoteelem.getSize().getHeight())/ 2;604 if (swipe_startxratio < 10) {605 swipe_startxratio = 10;606 }607 if (swipe_endxratio >= pagewidth) {608 swipe_endxratio = (int) (pagewidth-10);609 }610 if(direction.trim().equalsIgnoreCase("left"))611 driver.swipe(swipe_startxratio, yratio, swipe_endxratio, yratio, 1);612 if(direction.trim().equalsIgnoreCase("right"))613 driver.swipe(swipe_endxratio, yratio, swipe_startxratio, yratio, 1);614 }615 public void ChangeOrientation(ScreenOrientation orientation) {616 try {617 driver.rotate(orientation);618 /* driver.execute(DriverCommand.SET_SCREEN_ORIENTATION, ImmutableMap.of(619 "orientation", orientation.value().toUpperCase()));*/620 }catch (Exception e) {621 e.printStackTrace();622 }623 }624 /**625 * @author Cigniti626 * @param by627 * @return628 */629 public boolean IsElementVisible(final By by) {630 Boolean flag=false;631 try {632 wait = new WebDriverWait(driver, 10);633 wait.until(ExpectedConditions.presenceOfElementLocated(by));634 if ((driver.findElement(by).getSize().height == 0)&& (driver.findElement(by).getSize().width == 0)) {635 flag=false;636 } else {637 flag=true;638 }639 } catch (Exception e1){640 flag=false;641 }642 return flag;643 }644 public void SwipeTop(WebElement element) {645 try {646 AndroidElement elemIOS = (AndroidElement) element;647 elemIOS.swipe(SwipeElementDirection.UP, 0);648 } catch (Exception e1) {649 }650 }651 public void setGeoLocation(double latitude, double longitude) {652 Location loc = new Location(latitude, longitude, 0);653 driver.setLocation(loc);654 try {655 Thread.sleep(2000);656 } catch (Exception e) {657 }658 }659 public void setGeoLocation() {660 setGeoLocation(661 Double.valueOf(42.346886),662 Double.valueOf(-71.075529));663 }664 /**665 * @author Cigniti666 * @param alertShouldBeThereOrNot667 * @param waitingTime668 * @return669 */670 public boolean assertLocationAlertPresent(boolean alertShouldBeThereOrNot,671 Long waitingTime) {672 WebDriverWait wait = new WebDriverWait(driver, waitingTime);673 Alert alert = null;674 try {675 alert = wait.until(ExpectedConditions.alertIsPresent());676 } catch (TimeoutException e) {677 }678 Set<String> windowHandles = driver.getWindowHandles();679 if (windowHandles.size() > 1 && alertShouldBeThereOrNot == true) {680 alert = driver.switchTo().alert();681 /**682 * The alert text should be the one that is shown on IPhone/IPad. It683 * should have Allow and Dont Allow buttons.684 */685 String alertText = alert.getText();686 if (!alertText687 .equals("\"Safari\" Would Like to Use Your Current Location")) {688 alert = null;689 }690 }691 if (alert != null) {692 System.out.println("alert is present");693 } else {694 System.out.println("alert is not present");695 }696 if (alertShouldBeThereOrNot == true && alert != null) {697 return true;698 } else if (alertShouldBeThereOrNot == true && alert == null) {699 return false;700 }701 if (alertShouldBeThereOrNot == false && alert != null) {702 return false;703 } else if (alertShouldBeThereOrNot == false && alert == null) {704 return true;705 } else706 return false;707 }708 @SuppressWarnings({ "rawtypes", "unchecked" })709 public AndroidDriver SwitchToWebView(AndroidDriver driver2) {710 try {711 Set<String> contextNames = driver2.getContextHandles();712 if(contextNames.size()>1){713 for(String contextType : contextNames){714 if (contextType.toLowerCase().contains("webview_com.piti")) {715 driver2.context(contextType); // set context to WEBVIEW_1716 driver = driver2;717 System.out.println(driver.getContext());718 return driver2;719 } 720 }721 }722 } 723 catch (Exception e) {724 e.printStackTrace();725 }726 return driver2;727 }728 @SuppressWarnings("rawtypes")729 public AndroidDriver SwichToNativeView(AndroidDriver driver2) {730 try {731 driver2.context("NATIVE_APP");732 this.driver = driver2;733 return driver2;734 } catch (Exception e) {735 return null;736 }737 }738 /**739 * @author Cigniti740 * @param LocatorType741 * @param LocatorString742 * @param timeoutInSeconds743 * @return744 */745 @SuppressWarnings("unchecked")746 public List<WebElement> FindElements(MobileLocator LocatorType,String LocatorString, int timeoutInSeconds) {747 List<WebElement> webElement;748 WebDriverWait wait;749 try {750 switch (LocatorType) {751 case ByAccessibilityId:752 if (timeoutInSeconds > 0) {753 wait = new WebDriverWait(driver, timeoutInSeconds);754 webElement = wait.until(ExpectedConditions755 .visibilityOfAllElementsLocatedBy(MobileBy756 .AccessibilityId(LocatorString)));757 } else {758 webElement = driver.findElements(MobileBy759 .AccessibilityId(LocatorString));760 }761 break;762 case ByXPath:763 if (timeoutInSeconds > 0) {764 wait = new WebDriverWait(driver, timeoutInSeconds);765 webElement = driver.findElements(MobileBy.xpath(LocatorString));766 // webElement = wait.until(767 // ExpectedConditions.visibilityOfAllElementsLocatedBy(MobileBy.xpath(LocatorString)));768 } else {769 webElement = driver.findElements(MobileBy.xpath(LocatorString));770 }771 break;772 case ByClassName:773 if (timeoutInSeconds > 0) {774 wait = new WebDriverWait(driver, timeoutInSeconds);775 webElement = driver.findElements(MobileBy.className(LocatorString));776 // webElement = wait.until(777 // ExpectedConditions.visibilityOfAllElementsLocatedBy(MobileBy.className(LocatorString)));778 } else {779 webElement = driver.findElements(MobileBy.className(LocatorString));780 }781 break;782 case AndroidUIAutomator:783 if (timeoutInSeconds > 0) {784 wait = new WebDriverWait(driver, timeoutInSeconds);785 webElement = wait.until(ExpectedConditions786 .visibilityOfAllElementsLocatedBy(MobileBy787 .IosUIAutomation(LocatorString)));788 } else {789 webElement = driver.findElements(MobileBy.IosUIAutomation(LocatorString));790 }791 break;792 default:793 return null;794 }795 return webElement;796 } catch (Exception e) {797 return null;798 }799 }800 /**801 * @author Cigniti802 * @param LocatorType803 * @param LocatorString804 * @param timeoutInSeconds805 * @return806 */807 public boolean isElementPresent(MobileLocator LocatorType,String LocatorString, Integer timeoutInSeconds) {808 if (FindElement(LocatorType, LocatorString, timeoutInSeconds) != null) {809 return true;810 } else {811 return false;812 }813 }814 /**815 * @author Cigniti816 * @param mobBy817 * @param timeoutInSeconds818 * @return819 */820 public boolean isElementPresent(By mobBy, Integer timeoutInSeconds) {821 if (FindElement(mobBy, timeoutInSeconds) != null) {822 return true;823 } else {824 return false;825 }826 }827 /**828 * @author Cigniti829 * @param e830 * @return831 */832 public String getStackTraceAsString(Object e) {833 Exception ex = null;834 try {835 ex = (Exception) e;836 StringBuilder sb = new StringBuilder();837 for (StackTraceElement element : ex.getStackTrace()) {838 sb.append(element.toString());839 sb.append("][");840 }841 return "<b>" + ex.getClass().toString().toUpperCase()842 + "</b> Here is the stacktrace: " + sb.toString();843 } catch (Exception e2) {844 return "Stack trace not available.";845 }846 }847 /**848 * @author Cigniti849 * @param element850 * @param index851 */852 public void ScrollToUIATableViewUsingCellIndex(WebElement element, int index) {853 try {854 ((AndroidElement) element).findElementByAndroidUIAutomator(".cells()["855 + index + "].scrollToVisible();");856 } catch (Exception e) {...

Full Screen

Full Screen

MobileBy.java

Source:MobileBy.java Github

copy

Full Screen

...44 }45 @SuppressWarnings("unchecked")46 @Override public List<WebElement> findElements(SearchContext context) {47 return (List<WebElement>) ((FindsByFluentSelector<?>) context)48 .findElements(selector.toString(), getLocatorString());49 }50 @Override public WebElement findElement(SearchContext context) {51 return ((FindsByFluentSelector<?>) context)52 .findElement(selector.toString(), getLocatorString());53 }54 /**55 * Read https://developer.apple.com/library/tvos/documentation/DeveloperTools/56 * Conceptual/InstrumentsUserGuide/UIAutomation.html57 *58 * @param iOSAutomationText is iOS UIAutomation string59 * @return an instance of {@link io.appium.java_client.MobileBy.ByIosUIAutomation}60 */61 public static By IosUIAutomation(final String iOSAutomationText) {62 return new ByIosUIAutomation(iOSAutomationText);63 }64 /**65 * Read http://developer.android.com/intl/ru/tools/testing-support-library/66 * index.html#uia-apis67 * @param uiautomatorText is Android UIAutomator string68 * @return an instance of {@link io.appium.java_client.MobileBy.ByAndroidUIAutomator}69 */70 public static By AndroidUIAutomator(final String uiautomatorText) {71 return new ByAndroidUIAutomator(uiautomatorText);72 }73 /**74 * About Android accessibility75 * https://developer.android.com/intl/ru/training/accessibility/accessible-app.html76 * About iOS accessibility77 * https://developer.apple.com/library/ios/documentation/UIKit/Reference/78 * UIAccessibilityIdentification_Protocol/index.html79 * @param accessibilityId id is a convenient UI automation accessibility Id.80 * @return an instance of {@link io.appium.java_client.MobileBy.ByAndroidUIAutomator}81 */82 public static By AccessibilityId(final String accessibilityId) {83 return new ByAccessibilityId(accessibilityId);84 }85 /**86 * This locator strategy is available in XCUITest Driver mode87 * @param iOSClassChainString is a valid class chain locator string.88 * See <a href="https://github.com/facebook/WebDriverAgent/wiki/Queries">89 * the documentation</a> for more details90 * @return an instance of {@link io.appium.java_client.MobileBy.ByIosClassChain}91 */92 public static By iOSClassChain(final String iOSClassChainString) {93 return new ByIosClassChain(iOSClassChainString);94 }95 /**96 * This locator strategy is available in XCUITest Driver mode97 * @param iOSNsPredicateString is an an iOS NsPredicate String98 * @return an instance of {@link io.appium.java_client.MobileBy.ByIosNsPredicate}99 */100 public static By iOSNsPredicateString(final String iOSNsPredicateString) {101 return new ByIosNsPredicate(iOSNsPredicateString);102 }103 public static By windowsAutomation(final String windowsAutomation) {104 return new ByWindowsAutomation(windowsAutomation);105 }106 107 public static class ByIosUIAutomation extends MobileBy implements Serializable {108 public ByIosUIAutomation(String iOSAutomationText) {109 super(MobileSelector.IOS_UI_AUTOMATION, iOSAutomationText);110 }111 /**112 * @throws WebDriverException when current session doesn't support the given selector or when113 * value of the selector is not consistent.114 * @throws IllegalArgumentException when it is impossible to find something on the given115 * {@link SearchContext} instance116 */117 @SuppressWarnings("unchecked")118 @Override119 public List<WebElement> findElements(SearchContext context) throws WebDriverException,120 IllegalArgumentException {121 Class<?> contextClass = context.getClass();122 if (FindsByIosUIAutomation.class.isAssignableFrom(contextClass)) {123 return FindsByIosUIAutomation.class.cast(context)124 .findElementsByIosUIAutomation(getLocatorString());125 }126 if (FindsByFluentSelector.class.isAssignableFrom(context.getClass())) {127 return super.findElements(context);128 }129 throw formIllegalArgumentException(contextClass, FindsByIosUIAutomation.class,130 FindsByFluentSelector.class);131 }132 /**133 * @throws WebDriverException when current session doesn't support the given selector or when134 * value of the selector is not consistent.135 * @throws IllegalArgumentException when it is impossible to find something on the given136 * {@link SearchContext} instance137 */138 @Override public WebElement findElement(SearchContext context) throws WebDriverException,139 IllegalArgumentException {140 Class<?> contextClass = context.getClass();141 if (FindsByIosUIAutomation.class.isAssignableFrom(contextClass)) {142 return ((FindsByIosUIAutomation<?>) context)143 .findElementByIosUIAutomation(getLocatorString());144 }145 if (FindsByFluentSelector.class.isAssignableFrom(context.getClass())) {146 return super.findElement(context);147 }148 throw formIllegalArgumentException(contextClass, FindsByIosUIAutomation.class,149 FindsByFluentSelector.class);150 }151 @Override public String toString() {152 return "By.IosUIAutomation: " + getLocatorString();153 }154 }155 public static class ByAndroidUIAutomator extends MobileBy implements Serializable {156 public ByAndroidUIAutomator(String uiautomatorText) {157 super(MobileSelector.ANDROID_UI_AUTOMATOR, uiautomatorText);158 }159 /**160 * @throws WebDriverException when current session doesn't support the given selector or when161 * value of the selector is not consistent.162 * @throws IllegalArgumentException when it is impossible to find something on the given163 * {@link SearchContext} instance164 */165 @SuppressWarnings("unchecked")166 @Override167 public List<WebElement> findElements(SearchContext context) throws WebDriverException,168 IllegalArgumentException {169 Class<?> contextClass = context.getClass();170 if (FindsByAndroidUIAutomator.class.isAssignableFrom(contextClass)) {171 return FindsByAndroidUIAutomator.class.cast(context)172 .findElementsByAndroidUIAutomator(getLocatorString());173 }174 if (FindsByFluentSelector.class.isAssignableFrom(context.getClass())) {175 return super.findElements(context);176 }177 throw formIllegalArgumentException(contextClass, FindsByAndroidUIAutomator.class,178 FindsByFluentSelector.class);179 }180 /**181 * @throws WebDriverException when current session doesn't support the given selector or when182 * value of the selector is not consistent.183 * @throws IllegalArgumentException when it is impossible to find something on the given184 * {@link SearchContext} instance185 */186 @Override public WebElement findElement(SearchContext context) throws WebDriverException,187 IllegalArgumentException {188 Class<?> contextClass = context.getClass();189 if (FindsByAndroidUIAutomator.class.isAssignableFrom(contextClass)) {190 return FindsByAndroidUIAutomator.class.cast(context)191 .findElementByAndroidUIAutomator(getLocatorString());192 }193 if (FindsByFluentSelector.class.isAssignableFrom(context.getClass())) {194 return super.findElement(context);195 }196 throw formIllegalArgumentException(contextClass, FindsByAndroidUIAutomator.class,197 FindsByFluentSelector.class);198 }199 @Override public String toString() {200 return "By.AndroidUIAutomator: " + getLocatorString();201 }202 }203 public static class ByAccessibilityId extends MobileBy implements Serializable {204 public ByAccessibilityId(String accessibilityId) {205 super(MobileSelector.ACCESSIBILITY, accessibilityId);206 }207 /**208 * @throws WebDriverException when current session doesn't support the given selector or when209 * value of the selector is not consistent.210 * @throws IllegalArgumentException when it is impossible to find something on the given211 * {@link SearchContext} instance212 */213 @SuppressWarnings("unchecked")214 @Override215 public List<WebElement> findElements(SearchContext context) throws WebDriverException,216 IllegalArgumentException {217 Class<?> contextClass = context.getClass();218 if (FindsByAccessibilityId.class.isAssignableFrom(contextClass)) {219 return FindsByAccessibilityId.class.cast(context)220 .findElementsByAccessibilityId(getLocatorString());221 }222 if (FindsByFluentSelector.class.isAssignableFrom(context.getClass())) {223 return super.findElements(context);224 }225 throw formIllegalArgumentException(contextClass, FindsByAccessibilityId.class,226 FindsByFluentSelector.class);227 }228 /**229 * @throws WebDriverException when current session doesn't support the given selector or when230 * value of the selector is not consistent.231 * @throws IllegalArgumentException when it is impossible to find something on the given232 * {@link SearchContext} instance233 */234 @Override public WebElement findElement(SearchContext context) throws WebDriverException,235 IllegalArgumentException {236 Class<?> contextClass = context.getClass();237 if (FindsByAccessibilityId.class.isAssignableFrom(contextClass)) {238 return FindsByAccessibilityId.class.cast(context)239 .findElementByAccessibilityId(getLocatorString());240 }241 if (FindsByFluentSelector.class.isAssignableFrom(context.getClass())) {242 return super.findElement(context);243 }244 throw formIllegalArgumentException(contextClass, FindsByAccessibilityId.class,245 FindsByFluentSelector.class);246 }247 @Override public String toString() {248 return "By.AccessibilityId: " + getLocatorString();249 }250 }251 public static class ByIosClassChain extends MobileBy implements Serializable {252 protected ByIosClassChain(String locatorString) {253 super(MobileSelector.IOS_CLASS_CHAIN, locatorString);254 }255 /**256 * @throws WebDriverException when current session doesn't support the given selector or when257 * value of the selector is not consistent.258 * @throws IllegalArgumentException when it is impossible to find something on the given259 * {@link SearchContext} instance260 */261 @SuppressWarnings("unchecked")262 @Override public List<WebElement> findElements(SearchContext context) {263 Class<?> contextClass = context.getClass();264 if (FindsByIosClassChain.class.isAssignableFrom(contextClass)) {265 return FindsByIosClassChain.class.cast(context)266 .findElementsByIosClassChain(getLocatorString());267 }268 if (FindsByFluentSelector.class.isAssignableFrom(context.getClass())) {269 return super.findElements(context);270 }271 throw formIllegalArgumentException(contextClass, FindsByIosClassChain.class,272 FindsByFluentSelector.class);273 }274 /**275 * @throws WebDriverException when current session doesn't support the given selector or when276 * value of the selector is not consistent.277 * @throws IllegalArgumentException when it is impossible to find something on the given278 * {@link SearchContext} instance279 */280 @Override public WebElement findElement(SearchContext context) {281 Class<?> contextClass = context.getClass();282 if (FindsByIosClassChain.class.isAssignableFrom(contextClass)) {283 return FindsByIosClassChain.class.cast(context)284 .findElementByIosClassChain(getLocatorString());285 }286 if (FindsByFluentSelector.class.isAssignableFrom(context.getClass())) {287 return super.findElement(context);288 }289 throw formIllegalArgumentException(contextClass, FindsByIosClassChain.class,290 FindsByFluentSelector.class);291 }292 @Override public String toString() {293 return "By.IosClassChain: " + getLocatorString();294 }295 }296 public static class ByIosNsPredicate extends MobileBy implements Serializable {297 protected ByIosNsPredicate(String locatorString) {298 super(MobileSelector.IOS_PREDICATE_STRING, locatorString);299 }300 /**301 * @throws WebDriverException when current session doesn't support the given selector or when302 * value of the selector is not consistent.303 * @throws IllegalArgumentException when it is impossible to find something on the given304 * {@link SearchContext} instance305 */306 @SuppressWarnings("unchecked")307 @Override public List<WebElement> findElements(SearchContext context) {308 Class<?> contextClass = context.getClass();309 if (FindsByIosNSPredicate.class.isAssignableFrom(contextClass)) {310 return FindsByIosNSPredicate.class.cast(context)311 .findElementsByIosNsPredicate(getLocatorString());312 }313 if (FindsByFluentSelector.class.isAssignableFrom(context.getClass())) {314 return super.findElements(context);315 }316 throw formIllegalArgumentException(contextClass, FindsByIosNSPredicate.class,317 FindsByFluentSelector.class);318 }319 /**320 * @throws WebDriverException when current session doesn't support the given selector or when321 * value of the selector is not consistent.322 * @throws IllegalArgumentException when it is impossible to find something on the given323 * {@link SearchContext} instance324 */325 @Override public WebElement findElement(SearchContext context) {326 Class<?> contextClass = context.getClass();327 if (FindsByIosNSPredicate.class.isAssignableFrom(contextClass)) {328 return FindsByIosNSPredicate.class.cast(context)329 .findElementByIosNsPredicate(getLocatorString());330 }331 if (FindsByFluentSelector.class.isAssignableFrom(context.getClass())) {332 return super.findElement(context);333 }334 throw formIllegalArgumentException(contextClass, FindsByIosNSPredicate.class,335 FindsByFluentSelector.class);336 }337 @Override public String toString() {338 return "By.IosNsPredicate: " + getLocatorString();339 }340 }341 public static class ByWindowsAutomation extends MobileBy implements Serializable {342 protected ByWindowsAutomation(String locatorString) {343 super(MobileSelector.WINDOWS_UI_AUTOMATION, locatorString);344 }345 /**346 * @throws WebDriverException when current session doesn't support the given selector or when347 * value of the selector is not consistent.348 * @throws IllegalArgumentException when it is impossible to find something on the given349 * {@link SearchContext} instance350 */351 @SuppressWarnings("unchecked")...

Full Screen

Full Screen

LinksPage.java

Source:LinksPage.java Github

copy

Full Screen

...96 int defaultExpiration = DateUtils.minExpirationDate(97 OCCapability.getInstance().expirationDateDays(),98 Integer.valueOf(days)99 );100 String dateToSet = DateUtils.dateInDaysAndroidFormat(Integer.toString(defaultExpiration));101 Log.log(Level.FINE, "default: " + OCCapability.getInstance().expirationDateDays()102 + ". Days: " + days + ". Days to set: " + defaultExpiration + " Date to set: " + dateToSet);103 if (driver.findElements(new MobileBy.ByAccessibilityId(dateToSet)).isEmpty()) {104 Log.log(Level.FINE, "Date not found, next page");105 nextButton.click();106 }107 driver.findElement(new MobileBy.ByAccessibilityId(dateToSet)).click();108 okButton.click();109 }110 public boolean isPasswordEnabled(String itemName)111 throws IOException, SAXException, ParserConfigurationException {112 boolean switchEnabled = true;113 boolean passVisible;114 if (!isPasswordEnforced(itemName)) {115 switchPassword = (MobileElement) driver.findElement(By.id(switchPasswordId));116 switchEnabled = parseIntBool(switchPassword.getAttribute("checked"));117 }118 passVisible = textPassword.isDisplayed();119 return switchEnabled && passVisible;120 }121 public void selectDownloadView() {122 Log.log(Level.FINE, "Starts: Select Download / View");123 downloadViewOption.click();124 }125 public void selectDownloadViewUpload() {126 Log.log(Level.FINE, "Starts: Select Download / View / Upload");127 downloadViewUploadOption.click();128 }129 public void selectUploadOnly() {130 Log.log(Level.FINE, "Starts: Select Upload Only (File drop)");131 uploadOnlyOption.click();132 }133 public boolean checkPermissions(String permissions) {134 Log.log(Level.FINE, "Starts: Check permissions: " + permissions);135 switch (permissions) {136 case ("1"): {137 if (parseIntBool(downloadViewOption.getAttribute("checked"))) {138 Log.log(Level.FINE, "Download / View is selected");139 return true;140 }141 }142 case ("15"): {143 if (parseIntBool(downloadViewUploadOption.getAttribute("checked"))) {144 Log.log(Level.FINE, "Download / View / Upload is selected");145 return true;146 }147 }148 case ("4"): {149 if (parseIntBool(uploadOnlyOption.getAttribute("checked"))) {150 Log.log(Level.FINE, "Upload only is selected");151 return true;152 }153 }154 }155 return false;156 }157 public boolean checkExpiration(String days) {158 Log.log(Level.FINE, "Starts: Check expiration in days: " + days);159 List<MobileElement> switchExpiration =160 (List<MobileElement>) driver.findElements(By.id(switchExpirationId));161 boolean switchEnabled = false;162 boolean dateCorrect = false;163 int expiration = DateUtils.minExpirationDate(164 OCCapability.getInstance().expirationDateDays(),165 Integer.parseInt(days)166 );167 String shortDate = DateUtils.shortDate(Integer.toString(expiration));168 Log.log(Level.FINE, "Date to check: " + shortDate + " Expiration: " + expiration);169 if (switchExpiration.isEmpty()) {170 switchEnabled = true;171 } else {172 switchEnabled = parseIntBool(switchExpiration.get(0).getAttribute("checked"));173 }174 Log.log(Level.FINE, "SwitchEnabled -> " + switchEnabled);175 if (switchEnabled) {176 dateCorrect = expirationDate.getText().equals(shortDate);177 }178 Log.log(Level.FINE, "Date Correct -> " + dateCorrect);179 return switchEnabled && dateCorrect;180 }181 public void close() {...

Full Screen

Full Screen

UIElement.java

Source:UIElement.java Github

copy

Full Screen

...107 getElement().sendKeys(keySequence);108 } else {109 for (int i = 0; i < keySequence.length(); i++) {110 char c = keySequence.charAt(i);111 String s = new StringBuilder().append(c).toString();112 getElement().sendKeys(s);113 }114 }115 }116 } catch (Exception e) {117 MobileElement m = (MobileElement) getElement();118 this.clearText();119 getElement().clear();120 m.setValue(keySequence);121 }122 } catch (Exception e) {123 Assert.fail("Not able to enter the text");124 }125 if (hideKeyboardAfterTyping)126 MobileDevice.hideKeyboard();127 return this;128 }129 130 public UIElement sendKeys(String keySequence) throws Throwable {131 return sendKeys(keySequence, true);132 }133 public UIElement setText(String text, boolean hideKeyboardAfterTyping) throws Throwable {134 MobileElement e = (MobileElement) getElement();135 136 this.clearText();137 this.sendKeys(text);138 139 if (hideKeyboardAfterTyping)140 MobileDevice.hideKeyboard();141 return this;142 }143 public WebElement clearText() throws Throwable {144 WebElement e= getElement();145 e.clear();146 return e;147 }148 /**149 * Wait for element to load150 * 151 * @param timeout152 */153 public UIElement waitFor(int timeout) throws Throwable {154 /*155 WebDriverWait waitObj = new WebDriverWait(DriverFactory.getDriver(), timeout);156 try {157 waitObj.until(ExpectedConditions.visibilityOfElementLocated(this.locator));158 } catch (Exception e) {159 logger.debug("Unable to wait for visibility of element due to: " + e.getMessage());160 }*/161 long startTime= System.currentTimeMillis();162 do {163 try {164 if(getElement().isDisplayed()) break;;165 } catch (Exception e) {166 continue;167 }168 } while ((System.currentTimeMillis()- startTime) < timeout * 1000);169 return this;170 }171 public boolean isDisplayed() {172 try {173 return getElement().isDisplayed();174 } catch (Throwable ex) {175 logger.debug(ex.getMessage());176 return false;177 }178 }179 public static UIElement byXpath(String locator) {180 return new UIElement(By.xpath(locator));181 }182 public static UIElement byPredicate(String locator) {183 return new UIElement(MobileBy.iOSNsPredicateString(locator));184 }185 public static UIElement byCSS(String locator) {186 return new UIElement(By.cssSelector(locator));187 }188 public static UIElement byId(String locator) {189 return new UIElement(By.id(locator));190 }191 public static UIElement byUISelector(String locator) {192 return new UIElement(MobileBy.AndroidUIAutomator(locator));193 }194 public static UIElement byName(String locator) {195 return new UIElement(By.name(locator));196 }197 public static UIElement byAccessibilityId(String locator) {198 return new UIElement(MobileBy.AccessibilityId(locator));199 }200 public static UIElement byClass(String locator) {201 return new UIElement(MobileBy.className(locator));202 }203 public String getAttribute(String attrName) throws Throwable {204 return getElement().getAttribute(attrName);205 }206 public void waitForNot(int timeout) throws Throwable {207 long startTime= System.currentTimeMillis();208 do {209 try {210 if(!getElement().isDisplayed()) return;211 } catch (Exception e) {212 return;213 }214 } while ((System.currentTimeMillis()- startTime) < timeout * 1000);215 /*216 WebDriverWait waitObj = new WebDriverWait(DriverFactory.getDriver(), timeout);217 try {218 waitObj.until(ExpectedConditions.invisibilityOfElementLocated(this.locator));219 } catch (Exception e) {220 logger.debug("Unable to wait for invisibility of element due to: " + e.getMessage());221 }*/222 }223 public UIElement swipeUpSlow() throws Throwable {224 for (int i = 0; i < 40; i++) {225 if (this.isDisplayed())226 break;227 MobileDevice.swipeUpSlowly();228 }229 return this;230 }231 public UIElement swipeUpSlow(int noOfTimes) throws Throwable {232 for (int i = 0; i < noOfTimes; i++) {233 if (this.isDisplayed())234 break;235 MobileDevice.swipeUpSlowly();236 }237 return this;238 }239 public void touch() throws Throwable {240 new TouchAction((AppiumDriver) (DriverFactory.getDriver())).tap(getElement()).perform();241 }242 public void tapCenter() throws Throwable {243 MobileElement m = (MobileElement) getElement();244 Point p = m.getCenter();245 new TouchAction((AppiumDriver) (DriverFactory.getDriver())).tap(p.x, p.y).perform();246 }247 public int getCount() throws Throwable {248 return getElements().size();249 }250 public Dimension getSize() throws Throwable {251 return getElement().getSize();252 }253 public int getHeight() throws Throwable {254 return getSize().getHeight();255 }256 public int getWidth() throws Throwable {257 return getSize().getWidth();258 }259 public Point getLocation() throws Throwable {260 return getElement().getLocation();261 }262 public int getX() throws Throwable {263 return getLocation().getX();264 }265 public int getY() throws Throwable {266 return getLocation().getY();267 }268 public void longPress(int seconds) throws Throwable {269 new TouchAction((AppiumDriver) (DriverFactory.getDriver())).longPress(getElement(), Duration.ofSeconds(seconds)).release().perform();270 }271 public UIElement sendCharacterByCharacter(String keySequence, boolean hideKeyboardAfterTyping) throws Throwable {272 for (int i = 0; i < keySequence.length(); i++) {273 char c = keySequence.charAt(i);274 String s = new StringBuilder().append(c).toString();275 getElement().sendKeys(s);276 }277 if (hideKeyboardAfterTyping)278 MobileDevice.hideKeyboard();279 return this;280 }281}...

Full Screen

Full Screen

FormHelper.java

Source:FormHelper.java Github

copy

Full Screen

...37 }3839 public void isNumKeyboardOpen() throws InterruptedException {40 Thread.sleep(2000);41 if (driver.getCapabilities().getPlatform().toString().equals("LINUX")){42 AndroidDriver android = (AndroidDriver) driver;43 Assert.assertTrue(android.isKeyboardShown());44 } else {45 assertThat("1",driver.findElementByAccessibilityId("1").isEnabled());46 assertThat("0",driver.findElementByAccessibilityId("0").isEnabled());47 //Assert.assertFalse(driver.findElements(MobileBy.ByAccessibilityId.AccessibilityId("Shift")).isEmpty());48 //Assert.assertFalse(driver.findElements(MobileBy.ByAccessibilityId.AccessibilityId("Delete")).isEmpty());49 }50 }51 public void isNumKeyboardClosed() {52 if (driver.getCapabilities().getPlatform().toString().equals("LINUX")){53 AndroidDriver android = (AndroidDriver) driver;54 Assert.assertFalse(android.isKeyboardShown());55 } else {56 try {57 driver.findElementByAccessibilityId("0").isEnabled();58 driver.findElementByAccessibilityId("1").isEnabled();59 Assert.assertTrue(false);60 } catch (NoSuchElementException e) {61 Assert.assertTrue(true);62 }63 Assert.assertTrue(driver.findElements(MobileBy.ByAccessibilityId.AccessibilityId("Shift")).isEmpty());64 Assert.assertTrue(driver.findElements(MobileBy.ByAccessibilityId.AccessibilityId("Delete")).isEmpty());65 }66 }67 public void isKeyboardOpen() {68 //String str = driver.findElement(MobileBy.ByAccessibilityId.AccessibilityId("Return")).toString();69 //boolean btn = driver.findElements(MobileBy.ByAccessibilityId.AccessibilityId("Return")).isEmpty();70 if (driver.getCapabilities().getPlatform().toString().equals("LINUX")){71 AndroidDriver android = (AndroidDriver) driver;72 Assert.assertTrue(android.isKeyboardShown());73 } else {74 Assert.assertFalse(driver.findElements(MobileBy.ByAccessibilityId.AccessibilityId("Return")).isEmpty());75 Assert.assertFalse(driver.findElements(MobileBy.ByAccessibilityId.AccessibilityId("space")).isEmpty());76 }77 }78 public void isKeyboardClosed() {79 if (driver.getCapabilities().getPlatform().toString().equals("LINUX")){80 AndroidDriver android = (AndroidDriver) driver;81 Assert.assertFalse(android.isKeyboardShown());82 } else {83 Assert.assertTrue(driver.findElements(MobileBy.ByAccessibilityId.AccessibilityId("Return")).isEmpty());84 Assert.assertTrue(driver.findElements(MobileBy.ByAccessibilityId.AccessibilityId("space")).isEmpty());85 }86 }8788 public void isNextDisabled() {89 Assert.assertTrue(!NextBtn.isEnabled());90 }91 public void isNextEnabled() {92 Assert.assertTrue(NextBtn.isEnabled());93 }94 public void goBack() {95 formButtons.get(4).click();96 }9798 public void verifyCodeTitle(String phone, String country_code) {99 if (driver.getCapabilities().getPlatform().toString().equals("LINUX")){100 Assert.assertThat(formStaticTexts.get(0).getAttribute("text"), containsString(country_code +" "+phone));101 } else {102 //String full_title = "We’ve sent the code to the "+ country_code +" "+phone;103 //Assert.assertEquals(formStaticTexts.get(0).getAttribute("value"),full_title);104 Assert.assertThat(formStaticTexts.get(3).getAttribute("value"), containsString(country_code +" "+phone));105 }106 }107 public void resendCode() throws InterruptedException {108 codeHaventReceived.click();109 Thread.sleep(33000);110 codeResend.click();111 Thread.sleep(2000);112 }113 public void verifyCodeError() {114 if(driver.getCapabilities().getPlatform().toString().equals("LINUX")){115 Assert.assertEquals(wrongCodeError.getAttribute("text"),"Wrong code");116 } else {117 Assert.assertEquals(wrongCodeError.getAttribute("value"),"Wrong code");118 }119 }120121 public void waitForCode() {122 FluentWait<WebDriver> wait = new FluentWait<WebDriver>(driver)123 .withTimeout(2, TimeUnit.MINUTES)124 .pollingEvery(10,TimeUnit.SECONDS)125 .ignoring(NoSuchElementException.class)126 .withMessage("Timeout waiting the code");127 wait.until(ExpectedConditions.elementToBeClickable(formButtons.get(2)));128 } ...

Full Screen

Full Screen

Alert.java

Source:Alert.java Github

copy

Full Screen

...17 18 public void ByAccessIdByIndex(String selector, String attr, String attrValue) {19 MobileElement element = driver.findElement(ByAccessibilityId.AccessibilityId(selector));20 waitForVisible(driver, element);21 Assert.assertEquals(element.getAttribute(attr).toString().toLowerCase().replace(" ", ""), attrValue.toString().toLowerCase().replace(" ", ""));22 System.out.println(element.getAttribute(attr).toString());23 }24 25 public void ByClassByIndex(String selector, int index, String textAlert) {26 List<MobileElement> element = driver.findElements(By.className(selector));27 String actual = element.get(index).getText();28 Assert.assertEquals(actual.replace(" ", "").replace("\n", "").toLowerCase(), textAlert.replace(" ", "").replace("\n", "").toLowerCase());29 System.out.println("Alert: " + actual);30 }31 32 public void ByTagByIndex(String selector, int index, String textAlert) {33 List<MobileElement> element = driver.findElements(By.tagName(selector));34 String actual = element.get(index).getText();35 Assert.assertEquals(actual.replace(" ", "").replace("\n", "").toLowerCase(), textAlert.replace(" ", "").replace("\n", "").toLowerCase());36 System.out.println("Alert: " + actual);...

Full Screen

Full Screen

Element.java

Source:Element.java Github

copy

Full Screen

...45 try {46 ele = driver.findElement(by);47 return ele;48 } catch (NoSuchElementException error) {49 // System.out.println("> Error: no such element: " + by.toString().toString());50 return null;51 }52 }53 public static String GetText(WebDriver driver, String name){54 WebElement ele = IsPresent(driver, name);55 if (ele != null){56 return ele.getText();57 }58 return "null";59 }60 public static boolean Click(WebDriver driver, String name){61 WebElement ele = IsPresent(driver, name);62 if (ele != null) {63 ele.click();...

Full Screen

Full Screen

ElementSearchCriteria.java

Source:ElementSearchCriteria.java Github

copy

Full Screen

...39 return By.partialLinkText(this.getByValue());40 }41 throw new AutomatorException("Unknown find by type");42 }43 public String toString() {44 return "Find by: " + findByType + ", Value: " + byValue;45 }46}...

Full Screen

Full Screen

toString

Using AI Code Generation

copy

Full Screen

1System.out.println(MobileBy.ByAccessibilityId.toString());2System.out.println(MobileBy.ByAndroidUIAutomator.toString());3System.out.println(MobileBy.ByIosUIAutomation.toString());4System.out.println(MobileBy.ByLinkText.toString());5System.out.println(MobileBy.ByPartialLinkText.toString());6System.out.println(MobileBy.ByTagName.toString());7System.out.println(MobileBy.ByXPath.toString());8System.out.println(MobileBy.ByClassName.toString());9System.out.println(MobileBy.ByCssSelector.toString());10System.out.println(MobileBy.ById.toString());11System.out.println(MobileBy.ByName.toString());12System.out.println(MobileBy.ByAndroidViewTag.toString());13System.out.println(MobileBy.ByAndroidViewText.toString());14System.out.println(MobileBy.ByAndroidDataMatcher.toString());15System.out.println(MobileBy.ByIosClassChain.toString());16System.out.println(MobileBy.ByIosNSPredicate.toString());

Full Screen

Full Screen

toString

Using AI Code Generation

copy

Full Screen

1By element = MobileBy.ByAccessibilityId.toString("elementId");2By element = MobileBy.ByAndroidUIAutomator.toString("elementId");3By element = MobileBy.ByIosUIAutomation.toString("elementId");4By element = MobileBy.ByIosNsPredicate.toString("elementId");5By element = MobileBy.ByIosClassChain.toString("elementId");6By element = MobileBy.ByImage.toString("elementId");7By element = MobileBy.ByAndroidViewTag.toString("elementId");8By element = MobileBy.ByAndroidDataMatcher.toString("elementId");9By element = MobileBy.ByAndroidViewMatcher.toString("elementId");10By element = MobileBy.ByChained.toString("elementId");11By element = MobileBy.ByAll.toString("elementId");12By element = MobileBy.ByPartialLinkText.toString("elementId");13By element = MobileBy.ByLinkText.toString("elementId");14By element = MobileBy.ByXPath.toString("elementId");15By element = MobileBy.ByCssSelector.toString("elementId");

Full Screen

Full Screen

toString

Using AI Code Generation

copy

Full Screen

1MobileElement element=driver.findElementByAccessibilityId("AccessibilityId");2System.out.println(element.toString());3MobileElement element=driver.findElementByAndroidUIAutomator("text(\"AccessibilityId\")");4System.out.println(element.toString());5MobileElement element=driver.findElementByIosUIAutomation("UIATarget.localTarget().frontMostApp().mainWindow().buttons()[\"AccessibilityId\"]");6System.out.println(element.toString());7MobileElement element=driver.findElementByImage("Image");8System.out.println(element.toString());9MobileElement element=driver.findElementByIosNSPredicate("value == \"AccessibilityId\"");10System.out.println(element.toString());11MobileElement element=driver.findElementByIosClassChain("**/XCUIElementTypeButton[`name == \"AccessibilityId\"`]");12System.out.println(element.toString());13MobileElement element=driver.findElementByIosUIAutomation("UIATarget.localTarget().frontMostApp().mainWindow().buttons()[\"AccessibilityId\"]");14System.out.println(element.toString());15MobileElement element=driver.findElementByIosUIAutomation("UIATarget.localTarget().frontMostApp().mainWindow().buttons()[\"AccessibilityId\"]");16System.out.println(element.toString());17MobileElement element=driver.findElementByIosUIAutomation("UIATarget.localTarget().frontMostApp().mainWindow().buttons()[\"AccessibilityId\"]");18System.out.println(element.toString());19MobileElement element=driver.findElementByIosUIAutomation("UIATarget.localTarget().frontMostApp().mainWindow().buttons()[\"AccessibilityId\"]");20System.out.println(element.toString());

Full Screen

Full Screen

toString

Using AI Code Generation

copy

Full Screen

1MobileElement element = driver.findElementByAccessibilityId("id");2System.out.println(element.toString());3MobileElement element = driver.findElement(By.id("id"));4System.out.println(element.toString());5MobileElement element = driver.findElement(MobileBy.AccessibilityId("id"));6System.out.println(element.toString());7MobileElement element = driver.findElement(MobileBy.id("id"));8System.out.println(element.toString());9MobileElement element = driver.findElement(MobileBy.name("id"));10System.out.println(element.toString());11MobileElement element = driver.findElement(MobileBy.xpath("id"));12System.out.println(element.toString());13MobileElement element = driver.findElement(MobileBy.AndroidUIAutomator("id"));14System.out.println(element.toString());15MobileElement element = driver.findElement(MobileBy.iOSNsPredicateString("id"));16System.out.println(element.toString());17MobileElement element = driver.findElement(MobileBy.iOSClassChain("id"));18System.out.println(element.toString());19MobileElement element = driver.findElement(MobileBy.iOSUIAutomation("id"));20System.out.println(element.toString());21MobileElement element = driver.findElement(MobileBy.image("id"));22System.out.println(element.toString());23MobileElement element = driver.findElement(MobileBy.iosClassChain("id"));24System.out.println(element.toString());25MobileElement element = driver.findElement(MobileBy.iosNsPredicateString("id"));26System.out.println(element.toString());27MobileElement element = driver.findElement(MobileBy.iosUIAutomation("id"));28System.out.println(element.toString());29MobileElement element = driver.findElement(MobileBy.linkText("id"));30System.out.println(element.toString());

Full Screen

Full Screen

toString

Using AI Code Generation

copy

Full Screen

1MobileElement element = driver.findElement(By.AccessibilityId("AccessibilityId"));2System.out.println(element.toString());3MobileElement element = driver.findElement(By.AndroidUIAutomator("text(\"AccessibilityId\")"));4System.out.println(element.toString());5MobileElement element = driver.findElement(By.IosUIAutomation("AccessibilityId"));6System.out.println(element.toString());7MobileElement element = driver.findElement(By.IosNsPredicate("AccessibilityId"));8System.out.println(element.toString());9MobileElement element = driver.findElement(By.IosClassChain("AccessibilityId"));10System.out.println(element.toString());11MobileElement element = driver.findElement(By.Image("AccessibilityId"));12System.out.println(element.toString());13MobileElement element = driver.findElement(By.Custom("AccessibilityId"));14System.out.println(element.toString());15MobileElement element = driver.findElement(By.AndroidViewTag("AccessibilityId"));16System.out.println(element.toString());17MobileElement element = driver.findElement(By.AndroidDataMatcher("AccessibilityId"));18System.out.println(element.toString());19MobileElement element = driver.findElement(By.AndroidViewMatcher("AccessibilityId"));20System.out.println(element.toString());21MobileElement element = driver.findElement(By.AndroidViewAccessibility("AccessibilityId"));22System.out.println(element.toString());23MobileElement element = driver.findElement(By.AndroidViewContentDesc("AccessibilityId"));24System.out.println(element.toString());25MobileElement element = driver.findElement(By.AndroidViewText("AccessibilityId

Full Screen

Full Screen

toString

Using AI Code Generation

copy

Full Screen

1By byObj = MobileBy.ByAccessibilityId("test-Username");2System.out.println(byObj.toString());3By byObj = MobileBy.ByAndroidUIAutomator("new UiSelector().description(\"test-Username\")");4System.out.println(byObj.toString());5By byObj = MobileBy.ByIosUIAutomation(".elements()[\"test-Username\"]");6System.out.println(byObj.toString());7By byObj = MobileBy.ByIosNsPredicate("name == \"test-Username\"");8System.out.println(byObj.toString());9By byObj = MobileBy.ByIosClassChain("**/XCUIElementTypeOther[`name == \"test-Username\"`]");10System.out.println(byObj.toString());11By byObj = MobileBy.ByImage("test-Username");12System.out.println(byObj.toString());

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 method in MobileBy.ByAccessibilityId

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful