harveyslash
harveyslash

Reputation: 6014

AndroidViewClient, unable to find a view

I am using android view client for testing out the UI. My hierarchy looks like(as seen from the monitor tool of android studio): enter image description here

What I want to do is get a handle on the ball , and perform a touch action on it.

However, I am not able to get it. I used :

from com.dtmilano.android.viewclient import ViewClient
print(ViewClient(*ViewClient.connectToDeviceOrExit()).findViewByTag("ImageView")
    ) as my python script. 

And the output says None(but clearly an image view is visible in the picture).

What am I doing wrong here ?

EDIT:

When I use culebra -G and click on the ball , I get this:

no_id1 = vc.findViewByIdOrRaise("id/no_id/1") com_facebook_orca___id_back_button = vc.findViewByIdOrRaise("com.facebook.orca:id/back_button") no_id3 = vc.findViewByIdOrRaise("id/no_id/3") no_id3 = vc.findViewWithTextOrRaise(u'High Score') com_facebook_orca___id_high_score_text = vc.findViewByIdOrRaise("com.facebook.orca:id/high_score_text") com_facebook_orca___id_high_score_text = vc.findViewWithTextOrRaise(u'29') no_id5 = vc.findViewByIdOrRaise("id/no_id/5") no_id5 = vc.findViewWithTextOrRaise(u'Current Best') com_facebook_orca___id_best_score_text = vc.findViewByIdOrRaise("com.facebook.orca:id/best_score_text") com_facebook_orca___id_best_score_text = vc.findViewWithTextOrRaise(u'1') There is no imageview here.

Also, when I do ViewClient.findViewById("com.facebook.orca:id/ball") , i get None.

Edit 2

This is the output of dump -a

View[ class=android.widget.FrameLayout index=0 selected=false checked=false clickable=false package=com.facebook.orca text= long-clickable=false enabled=true bounds=((0, 0), (1280, 672)) content-desc= focusable=false focused=false uniqueId=id/no_id/1 checkable=false resource-id= password=false class=android.widget.FrameLayout scrollable=false ] parent=None
View[ class=android.widget.ImageButton index=0 selected=false NAF=true clickable=true package=com.facebook.orca text= long-clickable=false enabled=true bounds=((0, 25), (64, 89)) content-desc= focusable=true focused=false uniqueId=id/no_id/2 checkable=false resource-id=com.facebook.orca:id/back_button password=false class=android.widget.ImageButton checked=false scrollable=false ]
parent=android.widget.FrameLayout View[ class=android.widget.TextView index=1 selected=false checked=false clickable=false package=com.facebook.orca text=High Score long-clickable=false enabled=true bounds=((1202, 35), (1270, 51)) content-desc= focusable=false focused=false uniqueId=id/no_id/3 checkable=false resource-id= password=false class=android.widget.TextView scrollable=false ]
parent=android.widget.FrameLayout View[ class=android.widget.TextView index=2 selected=false checked=false clickable=false package=com.facebook.orca text=29 long-clickable=false enabled=true bounds=((1226, 51), (1246, 76)) content-desc= focusable=false focused=false uniqueId=id/no_id/4 checkable=false resource-id=com.facebook.orca:id/high_score_text password=false class=android.widget.TextView scrollable=false ]
parent=android.widget.FrameLayout View[ class=android.widget.TextView index=4 selected=false checked=false clickable=false package=com.facebook.orca text=Current Best long-clickable=false enabled=true bounds=((591, 95), (689, 116)) content-desc= focusable=false focused=false uniqueId=id/no_id/5 checkable=false resource-id= password=false class=android.widget.TextView scrollable=false ]
parent=android.widget.FrameLayout View[ class=android.widget.TextView index=5 selected=false checked=false clickable=false package=com.facebook.orca text=1 long-clickable=false enabled=true bounds=((612, 116), (667, 233)) content-desc= focusable=false focused=false uniqueId=id/no_id/6 checkable=false resource-id=com.facebook.orca:id/best_score_text password=false class=android.widget.TextView scrollable=false ]
parent=android.widget.FrameLayout

Upvotes: 0

Views: 1246

Answers (1)

Diego Torres Milano
Diego Torres Milano

Reputation: 69189

I guess the problem the tag on the image is not ImageView. Tag is set using View.setTag() on you android app but I don't think you need it.

According to your hierarchy you can use ViewClient.findViewById("com.facebook.orca:id/ball") to get a reference to such View.

I would also recommend you to use culebra -G (see Culebra GUI) then touch on the ball image and culebra will generate the correct line to find the view and touch it.

Upvotes: 1

Related Questions