1

I am working on getting the layout view of an activity and then parsing to get the bound of the required item. I am using uiautomator view to get the layout view using "adb exec-out uiautomator dump /dev/tty" but I want it to get into a file so that I can use it for parsing using Linq to XML

var xml = XDocument.Load(output);

I have gone through answer at Is there a way to get current activity's layout and views via adb? but not getting much help.Please suggest some pointer over it.

Community
  • 1
  • 1
luckycse
  • 215
  • 1
  • 3
  • 13

2 Answers2

0

AndroidViewClient/culebra's dump tool lets you do precisely that and many, many more stuff

$ dump -b

gives you the View bounds, something like

android.widget.FrameLayout   ((0, 0), (1080, 2048))
   android.widget.TextView com.example.app:id/text Something ((64, 64), (221, 123))
   ...

More details here.

Diego Torres Milano
  • 65,697
  • 9
  • 111
  • 134
  • I don't think that I can use any other library and bound to use adb.exe. Also what if we don't have any particular ids for the item/button we want to click. It will be good if we can get the output in an xml and then parse it according to our use. adb exec-out uiautomator dump - it gives the output in a xml way but only issue is that I am not able to save it to a string/file which I can load in XDocument.Load(output). – luckycse May 01 '17 at 17:15
  • for the cases when you don't have IDs (or IDs are repeated) AndroidViewClient always assign a *unique ID* to all views. Don't understand what you mean by `bound`, but AVC uses `adbclient` which connects to `adb`. – Diego Torres Milano May 01 '17 at 17:44
  • Due to some environment constraint, I can't use other than adb.exe. I mean I can't install AndroidViewClient . By bounds I meant this value of the coordinates within which an item/button exist - for ex: ((64, 64), (221, 123)) – luckycse May 01 '17 at 18:23
  • Well, if you want to do it yourself, take a look at AVC's source code and see how it gets the dump for different API levels. That's the beauty of Open Source. – Diego Torres Milano May 01 '17 at 18:29
0

you can do this: adb shell uiautomator dump /storage/sdcard/uiAuto.xml

This puts the dump in a file 'uiAuto.xml'. You can now pull this to a local file and then read it.

To pull it use: adb pull /storage/sdcard/uiAuto.xml [anylocalfile]

Atish Sanyal
  • 199
  • 1
  • 3