How to write xpath if parent and childs having the same class name and store the elements in the list


How to find out xpath for the below situation for the native apps for the child and parent class name are same.

trying with class name able to retrieving the first row only. need to retrieve all rows.

can any one help me

Hi Pradeep,

Can you upload the Xpath of 2 or 3 cells than we can make a strategy to solve you issue,
meanwhile, i believe there two conditions are possible i.e…

1.All cell have same xpath-> In this case you can use
List element=driver.findElements(By.xpath(“xpath”)); , it will return list of all cell,

  1. Cell have different xpath :You can write Relative xpath to perform any action.

I think it will work please let me know you side.


Hi dharam ,

am new to appium,i have tried with the below xpath

findElementsByAndroidUIAutomator(“UiSelector().className(“classname[@index]””); and able to get only first row not able to get all the rows in the list…

could you help how to write relative xpath.

if am understand correct you are passing index of cell than you are getting only that row , instead of passing index try below code, i think it will help,

“List<Web_Element> elementsList = driver.findElements(By

for (WebElement webElement : elementsList)

Hi dharam,

still not able to get the LinearLayout[index 0 to 9] elements.

String xpath = “//android.widget.ListView/descendant::android.widget.LinearLayout”;

List <WebElement> ListByXpath = driver.findElements(By.xpath(xpath));

See if that works

1 Like

Thanks Umar. able to get the list content

Need one more clarification regarding “//android.widget.ListView/descendant::android.widget.LinearLayout”; here to get another child LinearLayout" content.


It shall return you all VISIBLE linearLayout elements. If there are more and are not visible Appium won’t return those.

Hi Umar ,
Am able to find the index of the Layout …

then i have to click each and every layout by using for loop with xpath is this workable.


Hi Pradeep

Give it a try and let us know if that works for you

Hi Umar,

I tried with below: but not working …if possible help me out of it.

List layoutindex=null;

	    layoutindex= d.findElementsByXPath("//android.widget.ListView/*");
	 for (int i=0;i<=layoutindex.size()-1;i++)


Please check this. Index strategy might not work. Get the list of elements and then loop it through and click the desired element. There might be a good chance you have to swipe if that element is not in screen view.

Hi umer,
List ListByXpath = driver.findElements(By.xpath(xpath)); in this statement what is the exact meaning of By.xpath(xpath)…
could you plz.

Hi umar ,

For the above post i understood the xpath difference,
am able to find out the index by using your statement also… but the thing is i need to click each index one by one…
am able to click only index=0 only …
Please help me to out of it.

How many elements are there in the list. If it has only one then only index 0 is available.

Actually its having 4…

You should be able to click on all of 4 elements. If size is 4 then you have 5 elements. Loop it through and click on each element.


Hi umer,
Same statement am using and posted above post only …
But am able to click on index 0 only…
for 1,2,3 coming out of the loop and displaying as element not found error

Can you send me the apk and necessary information. I will try to see what is going on.

Hi Guys , our team has found some thing that is useful to all of you about the query topic : for finding the xpath of child element inside any parent element :
use : driver.findElement(By.xpath(OR.getProperty(parent element))).findElement(“child element property”))