Search code examples
javaappium-android

How to scroll screen in android native app having recyclerview using appium


I am trying to automate an app which is built using recyclerview. There are totally 10 tiles and in one screen 1st four tiles will be visible and to get other tiles I need to move the screen upward. I tried to move the screen by finding co-ordinates and "(AndroidElement)driver.findElement(MobileBy.AndroidUIAutomator("new UiScrollable(new UiSelector().resourceIdMatches(\".*id/type_text\")).setMaxSearchSwipes(5).scrollIntoView("new UiSelector().text(\"" + text + "\"))"))" this but there is slightly movement in the screen and couldn't get the remaining tiles. Is there any way to scroll to the bottom of the screen so that I can get last tile also.


Solution

  • @Sammar Ahmad, yes you were right. I was using wrong element. I constantly tried and finally worked after using co-ordinates.Code looks something like below. Created scroll() in homepage class and called the same from my test class

    public void scroll(int x, int y) {
        int startY = (int) (driver.manage().window().getSize().getHeight() * 0.90);
        int endY = (int) (driver.manage().window().getSize().getHeight() * 0.10);
        TouchAction action = new TouchAction(driver);
        action.press(point(x, startY)).waitAction(waitOptions(ofSeconds(3))).moveTo(point(x, endY)).release().perform();
    }
    
    MobileElement startElement = (MobileElement) driver.findElementById("mention parent element here");
    Point location = startElement.getLocation();
        homepage.scroll(location.x,location.y);