ScrollTo doesn't work for Android RecyclerView

Hi,

I used appium scrollTo before, when we had ScrollView in our Android app, and after changing that view to the recyclerView it’s not possible to scroll. But manually it is possible to slide horizontal slider. Can someone help with this?

My old codes:

public void slide(By scroll, String text) throws InterruptedException {

    JavascriptExecutor js = (JavascriptExecutor) driver;
    HashMap<String, String> swipeObject = new HashMap<String, String>();
    try {
        String widId = ((RemoteWebElement) (driver.findElement(scroll))).getId();
        swipeObject.put("direction", "Right");
        swipeObject.put("element", widId);
        swipeObject.put("text", text);
        driver.getPageSource();
        js.executeScript("mobile: scrollTo", swipeObject);

        while(!isElementPresent(By.name(text)))
        {
            swipeObject.put("text", "MyText");
            js.executeScript("mobile: scrollTo", swipeObject);
            swipeObject.put("text", text);
            js.executeScript("mobile: scrollTo", swipeObject);
        }

    } catch (Exception e) {
        System.out.println("error occured");
    }
    Thread.sleep(2000);

With new version of java client these mobile gestures are deprecated. We cannot execute any javascript in native context any more

You can directly use methods

driver.scrollTo(“StringText”)
driver.scrollToExact(“StringText”)
driver.swipe()
TocuhActions class movetoElement method

1 Like