varunnadimpalli
varunnadimpalli

Reputation: 41

How to scroll up the list view in Appium

I am working on a android native app which has 11 elements in a list view but to go to that element i need to scroll up.What is the code to write in appium

i have tried the below but did not work

    WebElement listscroll = driver.findElementById("com.varun.one/list");
    TouchActions flick = new TouchActions(driver).flick(listscroll, 0, -50, 0);
    flick.perform();

Upvotes: 1

Views: 3291

Answers (2)

Azad Rahul
Azad Rahul

Reputation: 1

I know this is an old question, but as someone who searched far and wide the same question, I am just posting the solution I found for anyone who wanders in.

We can use the UiScrollable() method to scroll and find specific texts or look for specific attributes. UiScrollable() has a method called UiSelector() which can be used to specify the element inside which we need to scroll.

In Java, the code would be as follows:

public void UIA2ScrollElement(String locatorName, String locatorValue, String text) {
        
        String formattedText = String.format("\"%s\"", text);
        String formattedElement = String.format("%s(\"%s\")", locatorName, locatorValue);
        driver.findElement(AppiumBy.androidUIAutomator("new UiScrollable(new UiSelector()."+ formattedElement +").scrollIntoView(text("+ formattedText +"));"));
        
    }

With this function. we can specify the element inside which we need to scroll using the locator type and locator value we provide.

Upvotes: 0

Jitendra
Jitendra

Reputation: 319

Get the refernce of your listview

scrollObject = {}
element = driver.find_element(:class, 'android.widget.ListView')
scrollObject["element"] = element.ref

You need to mention the text of the listview item you searching for

scrollObject["text"]='Paris'

And then user scrollTo command, which will scroll through listview until it finds the text "Paris"

driver.execute_script("mobile: scrollTo", scrollObject)

Upvotes: 1

Related Questions