0

I am trying to scroll down to the bottom of the screen to a UI block using UiSelector class but it's not working as expected. Basically, when I run the code it does not scroll all the way to the bottom rather it the first pulls and then starts scrolling but stops in the middle of the screen and then it goes back and forth and fails (attached a screen recording). Below is the code I used:

myDriver.findElement(MobileBy.AndroidUIAutomator("new UiScrollable("
                + "new UiSelector().description(\"scrollview_train_tab\")).scrollIntoView("                      
                + "new UiSelector().textMatches(\"Games\"));"));

Here, myDriver is an instance of AndroidDriver. Please note that the app does not have resourceId so I am using content-desc to identify UI objects.

I have tried with the followings methods in UiSelector class: text(), textContains(),description(), textMatches() but no luck. All of these are resulting in the same.

Please check this screen recording

Appium Client/Version: Java/7.3.0
Appium Server: 1.18.0-1 (Desktop version)
Executed on Android Emulator with Android 8
OS: Windows 10

Can anybody help? Thanks in advance.

0

After spending quite some time and I have figured out that all the examples provided here http://appium.io/docs/en/writing-running-appium/tutorial/swipe-tutorial/ do not work for me.

However, I edited the example here slightly and it worked. Basically, I replaced scrollable(boolean val) method with description(String desc). Below are the sample working code .
Scroll down:

driver.findElement(MobileBy.AndroidUIAutomator("new UiScrollable(new UiSelector().description(\""+parentScrollViewId+"\")).scrollForward()"));

Scroll up:

driver.findElement(MobileBy.AndroidUIAutomator("new UiScrollable(new UiSelector().description(\""+parentScrollViewId+"\")).scrollBackward()"));

Below is the full working code:

public void scrollUntilElementFound(AppiumDriver<?> driver, MobileElement elementScrollTo,String parentScrollViewId) {//Scrolls until element is found
boolean elementFound = false;
while(elementFound==false) {
    try {
        if(elementScrollTo.isDisplayed()==true) {
            break;
        }
    }catch(Exception e) {
        elementFound=false;
    }
    try {
        driver.findElement(MobileBy.AndroidUIAutomator("new UiScrollable(new UiSelector().description(\""+parentScrollViewId+"\")).scrollForward()"));
    }catch(Exception e) {
        //Ignore error  
    }
}

}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.