Can't get all children of element ListView

hi everyone,
I’m new in appium and I have problem, so…

I use:
appium 1.3.4.1
java-client 2.1.0
android real device
os: Windows

uiautomatorviewer:

How can I get all children of ListView (in this case 5 elements)? I need this because for each of them (in loop) I want to check value in TextView element (marked in picture)

I tried something like this:

AndroidDriver _driver;
List<WebElement> list = _driver.findElementsByAndroidUIAutomator(“new UiSelector().className(“android.widget.ListView”).childSelector(new UiSelector().className(“android.widget.LinearLayout”))”);

and in this case the number of elements in the list is equals 1

WebElement element = _driver.findElement(By.className(“android.widget.ListView”));
List <WebElement> allElements = element.findElements(By.className(“android.widget.LinearLayout”));

but this doesn’t work that what I want. It returns 37 elements

So, anyone know how do this?
I almost forgot, only the ListView has id, so probably only solution is to use XPath

Identification by xpath helps better in these cases:

Once you click on List View, you can see the properties(You would have been posted those properties here, so that we can help better).

List<WebElement> list=driver.findElements(By.xpath("//you can include class of ListView[@resoruce-Id='etcc']/LinerLayout"
Syso(list.size())

List <WebElement> list = _driver.findElements(By.xpath("//android.widget.ListView[@resource-id=‘ELEMENT_ID’]/android.widget.LinearLayout"));

it works :slight_smile: thanks

1 Like

Hi All,

I have a Listview with an index 2.
resource-id - null
class Name - android.widget.ListView
Child details:
class Name - android.view.View
index - 0
content-desc - 12. MAN. Total price discount,
For this, i have used the following code.
List list=driver.findElements(By.xpath("//android.widget.ListView[@index=‘2’]/android.view.View[@index=‘1’]/android.view.View[@index=‘0’]"));
it is finding the element. But the click or tap or submit or pinch operations are not working. Could you please help me on this?

Thanks in advance…
I can provide more details if you need.

I have the same problem. Did you find out what was wrong?