【问题标题】:get the uiautomator dump in a file and then parse it to get the bounds在文件中获取 uiautomator 转储,然后对其进行解析以获取边界
【发布时间】:2017-05-01 16:08:46
【问题描述】:

我正在获取活动的布局视图,然后解析以获取所需项目的边界。 我正在使用 uiautomator 视图来获取使用 "adb exec-out uiautomator dump /dev/tty" 的布局视图,但我希望它进入一个文件,以便我可以使用它来使用 Linq to XML 进行解析

var xml = XDocument.Load(output);

我已经在Is there a way to get current activity's layout and views via adb? 上回答了,但没有得到太多帮助。请建议一些指针。

【问题讨论】:

  • 我认为目前没有办法代替解析

标签: android xml linq android-uiautomator


【解决方案1】:

AndroidViewClient/culebradump 工具可让您准确地做到这一点以及许多更多的事情

$ dump -b

为您提供视图边界,例如

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

更多详情here

【讨论】:

  • 我不认为我可以使用任何其他库并绑定使用 adb.exe。另外,如果我们没有要单击的项目/按钮的任何特定 ID,该怎么办。如果我们能得到一个 xml 的输出,然后根据我们的使用进行解析,那就太好了。 adb exec-out uiautomator dump - 它以 xml 方式提供输出,但唯一的问题是我无法将其保存到可以在 XDocument.Load(output) 中加载的字符串/文件中。
  • 对于没有 ID(或 ID 重复)的情况,AndroidViewClient 始终为所有视图分配一个唯一 ID。不明白bound 是什么意思,但AVC 使用adbclient 连接到adb
  • 由于环境限制,除了adb.exe我不能用。我的意思是我无法安装 AndroidViewClient 。边界是指项目/按钮所在的坐标值 - 例如:((64, 64), (221, 123))
  • 好吧,如果你想自己做,看看 AVC 的源代码,看看它是如何获取不同 API 级别的转储的。这就是开源的美妙之处。
【解决方案2】:

你可以这样做: adb shell uiautomator dump /storage/sdcard/uiAuto.xml

这会将转储放在文件“uiAuto.xml”中。你现在可以把它拉到一个本地文件然后读取它。

要拉它使用: adb pull /storage/sdcard/uiAuto.xml [anylocalfile]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-08-06
    • 2020-09-27
    • 2012-12-09
    • 1970-01-01
    • 2013-04-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多