How to take count of elements on list?

how to take count of elements on list when there are number of elemnts on list. and list is scrollable.

@sneha it is not likely that I will get you the correct answer without knowing the OS you are testing and the language you are using… Anyway, if it was ruby and you are correctly getting an array of elements, the usual array.size should work.

thank palas,
but im using java… and working with windows8

Using java and W8 means that you are trying to test Android I guess…

Anyway, isn’t the solution the same for java? As far as I remember, for java arrays .size() returns the size of the array.


array.size() works, but if list is scrollable then I hav to scroll it… and after again I hav to count number. so many times it gives repeated count… so what will solution to take exact count of elements on list if it is scrollable?

You mean because the elements are not visible in the screen (you need to scroll to access them) you can’t count how many of them do you have? I dont know about the Android version, but for iOS if I as for all the elements, using xpath, it returns me the visible and the invisible ones. But dont take this answer, I am not familiar with Android and java frameworks.

yaa… actually what happens, when we scroll the list, it take count from that element which see as first in the list. it again giving count only for that elemnts which is visible for webdriver… but if I want total count of elements(visible as well as invisible) then what should do? can you please explain with example?

Hi! did you solved this problem?

Hi all,

It think its too late to reply… i was just going through all the queries and i too faced this issue… And i solved it using below code…

Hope it might help any1…

String a = “Last element name”; /// last element in the list
Boolean found = false;

    while (!found){

        List<WebElement> ele = driver.findElements(""));
        int size=0;
         size = size+ele.size();

        for (int i = 0; i < size; i++) {
            String s;
            s = songs.get(i).getText();

            if (s.equals(a)) {
                found =true;


        driver.swipe(startx, starty, endx, endy, duration);}



I’m not testing on Android yet but I thought the page_source would return everything, including elements out of view. You can then execute counting elements against the page_source directly. Assuming that’s true, that would be the easiest way to simply count how many cells are in a scrollable tableview.

However, once you want to start clicking on the elements you’ll have to scroll them into view.

Please give me proper solution-
How to take count of visible and invisible element in list view.
when i am scroll down then it take repeated count of some element.
give me short and sweet code for taking visible and invisible element count in list

I am also stuck with the same problem. List has some dynamic elements, i want to count all of them and read the content. Please help need it urgently.

What if the id for the all elements in the list is same?

As user of the app how do you count that list? I guess you start counting, that you remember the last element characteristics (unique text, id, content-description, etc.) and scroll down and then keep counting. You know you are on the bottom when you scroll down and same last element characteristics is visible.

With code, you do that same. This is a code “problem” not an appium one.

No,as a user it doesn’t go far after reaching at bottom…but how to Handle this via Appium when all elements are of same id ?

if they have same id, thats better!

You get the array, and then you get the unique characteristics from last element of the array (maybe text is unique). Then you scroll down and get the array again. You only keep counting the elements from the unique element you had saved. If that element continues being the last of the array you have reached the bottom

Hi Harshal… Have you found any solution? I am also facing same issue.
Thanks in advance

Hi Sneha …Have you get solution? I am also facing same issue

If I don’t know last element then what should I do. My basic idea is to get all element which are off the screen too.

Imagine you have long list. By default most of apps use lazy loading. It means they load first let say 25 items and will load next when user will reach scroll end.

Basic answer to your question - not possible without scrolling.