Getting the actual size of the list

Hi,

I am stuck with a scenario where I am not able to get the actual size of the list view. I tried using all the locators possible. But I get the size of the list view which is only in the visible area. Suppose, the actual size of the list is 20 and only 10 elements are visible then the size of the list is shown as 10. Please help. Also the list is dynamic. So I can’t refer to a specific text or an element and scroll to that and get the size. I am hereby pasting a code snippet so that you guys can understand where I am going wrong.

List login= driver.findElementsById(“com.zee.gorb:id/slot_text”);
System.out.println(login.size());

Thanks in advance.

what i do in this scenario is something like:
WebElement parent = device.getDriverWrapper().getElement(By.id(""));
List child = parent.findElements(By.id(""));
int listSize = child.size();

the parent should be the layout that contains all the elements

That’s a known issue for Android ListViews. I’m not sure if the Android system development will ever expand the Uiautomator API to query ListView’s adapter’s lengths.

Have you considered writing this particular test case as an Espresso test? You’ll have access to your application’s internal APIs and you’ll be able to retrieve the adapter for your ListView’s adapter. It’s a white box test.

Hi @amarKumar

What attributes there are more in those elements? Any of those characteristics is unique? What you want to do with the list? just the size?

@Telmo_Cardoso

I actually want to find the blocked accounts from the list of accounts registered with an app. In order to do that I tried to take the size of the list (i.e. the total number of account). Then I thought of logging in with each one of them (which can be done by just clicking on any one of them). If I was able to log in properly, then the account would not be blocked, else it is blocked. This is my actual test case.

If the accounts names (for example) are unique you can get those names and store them, then check if the visible ones are blocked. Then you swipe down list, return the list again and remove the duplicated ones with your old list and so on until all list is verified (in final swipe, all list will be duplicated so you will remove all elements).