Click on a chile element


In my app I need to click on a child element and for some reason its not working.

This is the parent element: WebElement element = device.getDriverWrapper().getIosDriver().findElement(By.xpath("//UIACollectionView[1]/UIACollectionCell[4]"));

This element contains textview and a lock. I need to press on the lock.

This is the child element:
WebElement child = element.findElement(By.xpath("//UIAButton[1]"));;

Any idea what I do wrong?


Don’t use xpath when you’re searching within a parent element. Xpath on Appium will always search from the root of the UI hierarchy. Instead, you should try using By.className(“UIAButton”) when you’re searching for your child element.

1 Like

Do you mean that if I will use it like: WebElement child = element.findElementBy.className(“UIAButton”)) , I will get the button within this element?

You will find the first UIAButton child element under the parent referenced by the “element” variable. If there is only 1 button, then this is what you want. If there are more than 1 button, then you will get the first UIAButton element underneath “element”. If there are no buttons, you’ll get an exception.

1 Like