Can you do nested search for elements in appium?

On android nested elements have same ids within linear layout. So I am trying to search for elements within it.

is it possible to do something like this to search for elements within a linear layout?

driver.find_element_by_id("some_cell_id").find_by_xpath("//android.widget.seekbar")

Java is like - driver.findElements(By.Id (“some_cell_id”)).findElements(MobileBy.classname(“android.widget.seekbar”))

2 Likes

Thanks this works in python something like this:

driver.find_element_by_id("some_cell_id").find_elements_by_class_name("android.widget.seekbar")

Unfortunately you cannot call find_element_by_xpath() on an Webdriver Element, apparently that feature has not been implemented. See here: https://github.com/appium/appium/issues/25581

You can however call other find methods like find_element_by_class() against an element to find children, use XPATH axes, or use some custom code to programmatically compose XPATH by concatenating some XPATH snippets together then calling self.driver.find_element_by_xpath(your_custom_composed_xpath)

Learn about XPATH axis, it provides a LOT of useful methods for locating specific elements via relationships to other elements in the DOM, and you can continue to find very specific elements via attributes such as name.

Start here as it has clear, well detailed examples: http://www.xmlplease.com/axis

1 Like