Using Python, can I retrieve a list of available elements on a given page?

I’m attempting to determine what elements are present on a given page using the python bindings. Ideally I’d like to know the number of elements that exist on a given page and the xpath (and/or location) of the elements. I’m aware that the Appium Inspector can assist me with this, but I’ve got dynamically created cells which I’d like to keep track of during an Appium test. Thanks in advance for any assistance!

  • Craig

I suppose you want to find present elements which don’t contain any other elements, right?
Just write Python, which goes though each node recursively until endpoint and store elements to array or whatever. :slight_smile:

Care to elaborate on what you just explained? I’m not familiar with how the nodes come into play here. Also a bit new to Python. Thanks!

Well, I think that’s what you are looking for. Simplest solution:

Ruby:

elements = $driver.find_elements(:xpath, "//*[not(*)]")

Python:

elements = driver.find_elements_by_xpath("//*[not(*)]")

//*[not(*)] means, that you are looking for element with any tag which doesn't contain any other tag, i.e. element.

elements is an array of all elements. You can access them by index:

elements[index]
2 Likes

Thanks for the follow up response! Looks like I’ve got a lot more to learn about the how appium is working in the background!

You are welcome.
That’s not exactly Appium. That’s Selenium WebDriver itself.