This site is in read only mode. Please continue to browse, but replying, likes, and other actions are disabled for now.
1 / 13
May 2017

Is there any alternative for ScrollTo() and ScrollToExact()

  • created

    May '17
  • last reply

    May '17
  • 12

    replies

  • 3.2k

    views

  • 6

    users

  • 1

    like

  • 2

    links

e.g. Android:

   // by ID
    @AndroidFindBy(uiAutomator = "new UiScrollable(new UiSelector()).scrollIntoView("
            + "new UiSelector().resourceIdMatches(\".*id/publicity\"))")
    private List<AndroidElement> allowFriendsToSeeMe;
   
   // by Text
    public boolean tapMenuByText(String menuText) {
        System.out.println("  tap menu by text: "+menuText);
        try {
            return tapElement(driver.findElement(MobileBy
                    .AndroidUIAutomator("new UiScrollable(new UiSelector()).scrollIntoView("
                            + "new UiSelector().text(\""+menuText+"\"));")));
        } catch (Exception e) {
            return false;
        }
    }

@vijay.alapati you are lucky today for iOS:

public boolean tapItemByDescription(String text) {
        System.out.println("   tapItemByDescription(): " + text);

        // scroll to object
        JavascriptExecutor js = (JavascriptExecutor) driver;
        HashMap scrollObject = new HashMap<>();
        scrollObject.put("predicateString", "value == '" + text + "'");
        js.executeScript("mobile: scroll", scrollObject);

       // tap object
        WebElement el = ((IOSDriver) driver).findElementByIosNsPredicate("value = '" + text + "'");
        return tapElement((MobileElement) el); //tapElement just custom implementation. you may choose any way.
    }

// example of some other predicate string which we can use in above example:
    @iOSXCUITFindBy(iOSNsPredicate = "type == 'XCUIElementTypeStaticText' AND name == 'Change profile name'")
    private List<IOSElement> changeProfileNameDialogHeader;

@vijay.alapati @mathewkuruvila "tapElement" just custom function to maintain taps. There are 4 or even more ways to execute TAP with Appium. To make life easier to support i just do all taps through one function where i can easily change the way of tap and see how it is working in general across all screens.

Thank you @Aleksei
Is there any native method, like the UiScrollable for scroll in IOS. And also isn't the element location strategy using predicate deprecated in latest appium after migration to xcuitest

@mathewkuruvila i gave you scrollable for iOS which is very similar to Android. "predicateString" supports with latest iOS and Appium - no problem. just try and enjoy.