Navigating a screen hierarchy to find a specific element

I’m running Appium 1.4.13 and Ruby Mine 8.0.3 on a MacBook OS X 10.11.14, controlling an Android tablet v5.01. I want to find an element that may be on on the 2nd or 3rd screen or multiple screens down:


For example, how would I find element 2b, or 2c3, or know that element3b is the end of the line?

I have an application map, and could find an element via brute force on a known hierarchy, but of course something will change.

If someone could point me in the right direction, that would be great. Also, I’m a newbie.


How are you modeling your application? I recommend using a page object model to interact with your screens. Doing so would allow you to navigate through the screens and figure out where the object exists.

screens = [screen1, screen2, screen3]
screen_found = false
screens.each do |screen|
  if appium_driver.driver.find_element(:id, resource-id) 
    puts "element is on #{screen.class}"
    screen_found = screen
raise "some error" unless screen_found

Sorry, that wasn’t a very good example of the page object model…
but having a different screens would allow you to take an action on that screen after the element is found.

Hi, Will.

Thanks for getting back to me.

Unfortunately, I’m not the developer. I was handed some hardware, software, books, and a deadline.

Training is for Phase 2.

Actually, your code seems rather good.

I found


which looks like a good place to RTFM Other suggestions are welcome.

FWIW, here’s the path for one of the screen buttons:

xpath: //android.view.View[1]/android.widget.FrameLayout[1]/android.widget.RelativeLayout[1]/android.webkit.WebView[1]/android.webkit.WebView[1]/android.widget.Button[1].