Tuesday 15 January 2013

android - UIautomator how to get child by index or instance -



android - UIautomator how to get child by index or instance -

i utilize next code kid of uiautomator not working

uiobject = new uiobject(new uiselector().classname("android.widget.linearlayout").instance(2)); int cound = my.getchildcount(); for(int = cound - 1; >= 0; i--) { uiobject childmy2 = my.getchild(my.getselector().childselector(new uiselector().instance(i))); log.e("xface", "childmy2=" + childmy2.getclassname()); log.e("xface", "childmy2=" + childmy2.getbounds().tostring()); }

can help me ?

simplyfy question:how implementation function:

arraylist getallchild(uiobject node)

input:given node want getchild

return:all kid of given node

suppose have:

<parent> <child1> <child1.1></child1.1> <child1.2></child1.2> </child1> <child2> <child2.1></child2.1> <child2.2></child2.2> </child2> <child3> <child3.1></child3.1> <child3.2></child3.2> </child3> </parent>

bellow solution homecoming result kid 1, kid 2, kid 3

uiobject object = new uiobject(<uiselector parent>); int cnt = object.getchildcount(); for(int = 0; < cnt; i++) { uiobject eachitem = object.getchild(new uiselector().index(i)); }

if want kid 1.1, kid 1.2 , kid 2.1

uiobject object = new uiobject(<uiselector parent>); int cnt = object.getchildcount(); for(int = 0; < cnt; i++) { uiobject eachitem = object.getchild(new uiselector().index(i)) .getchild(<uiselector kid 1.1 or kid 1.2 ...>); // note: before getting should check whether has kid or not. }

android uiautomator

No comments:

Post a Comment