有没有办法通过adb获取当前活动的布局和视图?

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

有没有一种方法来获得当前的布局属性,如idpositiontext

uiautomatorviewer显示的相似。


手掌心
浏览 2350回答 3
3回答

慕妹3242003

使用adb shell uiautomator dump命令:Usage: uiautomator <subcommand> [options]Available subcommands:help: displays help messageruntest: executes UI automation tests&nbsp; &nbsp; runtest <class spec> [options]&nbsp; &nbsp; <class spec>: <JARS> < -c <CLASSES> | -e class <CLASSES> >&nbsp; &nbsp; &nbsp; <JARS>: a list of jar files containing test classes and dependencies. If&nbsp; &nbsp; &nbsp; &nbsp; the path is relative, it's assumed to be under /data/local/tmp. Use&nbsp; &nbsp; &nbsp; &nbsp; absolute path if the file is elsewhere. Multiple files can be&nbsp; &nbsp; &nbsp; &nbsp; specified, separated by space.&nbsp; &nbsp; &nbsp; <CLASSES>: a list of test class names to run, separated by comma. To&nbsp; &nbsp; &nbsp; &nbsp; a single method, use TestClass#testMethod format. The -e or -c option&nbsp; &nbsp; &nbsp; &nbsp; may be repeated. This option is not required and if not provided then&nbsp; &nbsp; &nbsp; &nbsp; all the tests in provided jars will be run automatically.&nbsp; &nbsp; options:&nbsp; &nbsp; &nbsp; --nohup: trap SIG_HUP, so test won't terminate even if parent process&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;is terminated, e.g. USB is disconnected.&nbsp; &nbsp; &nbsp; -e debug [true|false]: wait for debugger to connect before starting.&nbsp; &nbsp; &nbsp; -e runner [CLASS]: use specified test runner class instead. If&nbsp; &nbsp; &nbsp; &nbsp; unspecified, framework default runner will be used.&nbsp; &nbsp; &nbsp; -e <NAME> <VALUE>: other name-value pairs to be passed to test classes.&nbsp; &nbsp; &nbsp; &nbsp; May be repeated.&nbsp; &nbsp; &nbsp; -e outputFormat simple | -s: enabled less verbose JUnit style output.dump: creates an XML dump of current UI hierarchy&nbsp; &nbsp; dump [--verbose][file]&nbsp; &nbsp; &nbsp; [--compressed]: dumps compressed layout information.&nbsp; &nbsp; &nbsp; [file]: the location where the dumped XML should be stored, default is&nbsp; &nbsp; &nbsp; /storage/emulated/legacy/window_dump.xmlevents: prints out accessibility events until terminated默认情况下,它会将视图层次结构转储到 $EXTERNAL_STORAGE/window_dump.xmladb shell uiautomator dumpUI hierchary dumped to: /sdcard/window_dump.xml通常,您可能希望将该文件提取到PC进行进一步处理,这将是一个额外的步骤。但是有一个巧妙的技巧,它允许将转储和拉入组合成一个命令。使用/dev/tty转储目标将生成一个命令,将整个转储打印到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
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Android