有没有办法通过adb获取当前活动的布局和视图? [英] Is there a way to get current activity's layout and views via adb?

查看:1146
本文介绍了有没有办法通过adb获取当前活动的布局和视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

出于环境原因,我只能使用 adb 命令。

For environment reasons I can only use adb commands.

有没有办法获取当前的布局属性,例如 id position 文本

Is there a way to get the current layout attributes like id, position, text etc ?

类似于 uiautomatorviewer 显示。

Similar to what uiautomatorviewer shows.

推荐答案

使用 adb shell uiautomator dump 命令:

Usage: uiautomator <subcommand> [options]

Available subcommands:

help: displays help message

runtest: executes UI automation tests
    runtest <class spec> [options]
    <class spec>: <JARS> < -c <CLASSES> | -e class <CLASSES> >
      <JARS>: a list of jar files containing test classes and dependencies. If
        the path is relative, it's assumed to be under /data/local/tmp. Use
        absolute path if the file is elsewhere. Multiple files can be
        specified, separated by space.
      <CLASSES>: a list of test class names to run, separated by comma. To
        a single method, use TestClass#testMethod format. The -e or -c option
        may be repeated. This option is not required and if not provided then
        all the tests in provided jars will be run automatically.
    options:
      --nohup: trap SIG_HUP, so test won't terminate even if parent process
               is terminated, e.g. USB is disconnected.
      -e debug [true|false]: wait for debugger to connect before starting.
      -e runner [CLASS]: use specified test runner class instead. If
        unspecified, framework default runner will be used.
      -e <NAME> <VALUE>: other name-value pairs to be passed to test classes.
        May be repeated.
      -e outputFormat simple | -s: enabled less verbose JUnit style output.

dump: creates an XML dump of current UI hierarchy
    dump [--verbose][file]
      [--compressed]: dumps compressed layout information.
      [file]: the location where the dumped XML should be stored, default is
      /storage/emulated/legacy/window_dump.xml

events: prints out accessibility events until terminated

默认情况下,它将视图层次结构转储到 $ EXTERNAL_STORAGE / window_dump.xml

By default it dumps the views hierarchy to $EXTERNAL_STORAGE/window_dump.xml

adb shell uiautomator dump
UI hierchary dumped to: /sdcard/window_dump.xml

通常,您希望将该文件拉到PC上进行进一步处理,这是一个额外的步骤。但是,有一个巧妙的技巧可以将转储和拉取结合到一个命令中。使用 / dev / tty 作为转储目标将产生一个命令,该命令会将整个转储打印到 stdout

Usually you would want to pull that file to your PC for further processing which would be an extra step. But there is a neat trick which allows to combine dumping and pulling into a single command. Using /dev/tty as a dump destination would make a single command which would print the whole dump to the stdout:

adb exec-out uiautomator dump /dev/tty
<?xml version='1.0' encoding='UTF-8' standalone='yes' ?><hierarchy rotation="0"><node ...></node></hierarchy>UI hierchary dumped to: /dev/tty

这篇关于有没有办法通过adb获取当前活动的布局和视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆