Question

I'm trying to use UiAutomator to find an ImageView that is nested relatively deep inside a layout in an android app. This is a slimmed down version of the code I use to find it:

UiObject nextButton = new UiObject(new UiSelector().className(className)
                                                   .index(2));
nextButton.waitForExists(20000);
nextButton.clickAndWaitForNewWindow();

The layout (from UiAutomatorViewer) looks like this:

(0) FrameLayout
  (0) LinearLayout
    (0) FrameLayout
      (0) RelativeLayout
        (0) LinearLayout
          (0) RelativeLayout
            (0) RelativeLayout
              (0) TextView
          (1) RelativeLayout
            (0) LinearLayout
              (0) TextView
              (1) TextView
            (1) ImageView
          (2) RelativeLayout
            (0) ImageView
            (1) ImageView
          (3) LinearLayout
            (0) LinearLayout
              (0) ImageView
              (1) ImageView
              (2) ImageView       //<----- The one I'm after
            (1) TextView

The problem here is that UiAutomator can't find it. It starts up the UiWatcher and eventually fails with UiObjectNotFoundException. I can get it to work by pointing the way by specifying a few other layouts on the way down but I want to avoid doing that as far as possible. Is there a better way for me to look for this ImageView? I'm using APK 16 so resourceId's are out of the question unfortunately.

Was it helpful?

Solution 2

The answer to this was to use better hardware. On slow hardware it seems like UiAutomator simply could'nt iterate far enough through the layout regardless of how long time it was given.

OTHER TIPS

You can create a object for Framelayout then create a another object using FrameLayout object for ImageView and give Index(2) as there is no other index(2) is available for ImageView.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top