Using Wildcard in xpath is returning only first element

I have an xpath where the UIACollectionCell has indexes from 1 to 6 which returns 6 elements.
For ex:
//UIAApplication[1]/UIAWindow[4]/UIACollectionView[1]/UIACollectionCell[1]/UIAStaticText[1]
//UIAApplication[1]/UIAWindow[4]/UIACollectionView[1]/UIACollectionCell[2]/UIAStaticText[1]
//UIAApplication[1]/UIAWindow[4]/UIACollectionView[1]/UIACollectionCell[3]/UIAStaticText[1]
and so on. So i decided to use the wildcard character * in place of the indexes to find all elements.

But when i use the Wildcard character * , it is returning only first element. When i try the xpath in Xpath tester, it returns all the 6 elements.
List app_displayedRails_all = driver.findElements(By.xpath("//UIAApplication[1]/UIAWindow[4]/UIACollectionView[1]/UIACollectionCell[*]/UIAStaticText[1]"));

The above xpath only returns size 1 and returns the first element. Please help on where i am going wrong. Thank you

Try this driver.findElements(By.xpath("//UIAApplication[1]/UIAWindow[4]/UIACollectionView[1]/UIACollectionCell[*]/UIAStaticText");

2 Likes

That works! Thank you so much

@CrashTestDummy,
Had another doubt. What if even UIAStaticText has UIAStaticText[1] and UIAStaticText[2]. Would the above return both?