简体   繁体   English

使用Python或adb命令读取Android UI文本?

[英]Using Python or adb command to read Android UI text?

I was just wondering if there was a way to read the text displayed on a Android device's UI using python or any adb commands? 我只是想知道是否有一种方法可以使用python或任何adb命令来读取Android设备的UI上显示的文本?

I have found a module for python called "UIAutomator : https://github.com/xiaocong/uiautomator ", which can be used to dump the screen's contents, but it seems to be really slow and often unreliable in terms of connection to the android device. 我为python找到了一个名为“ UIAutomator: https : //github.com/xiaocong/uiautomator ”的模块,该模块可用于转储屏幕的内容,但它看起来确实很慢,而且在连接到屏幕上时通常不可靠android设备。

I also found google's own UIAutomator tool, but I needed something that can be used via a python script or an adb command to read the onscreen text. 我还找到了谷歌自己的UIAutomator工具,但是我需要一些可以通过python脚本或adb命令使用的东西来读取屏幕上的文本。

Any help would be appreciated. 任何帮助,将不胜感激。

Thanks in advance :) 提前致谢 :)

I have done a bit of research and found out two ways to read the UI's contents. 我做了一些研究,发现了两种读取UI内容的方法。

  1. Using AndroidViewClient's dump tool. 使用AndroidViewClient的转储工具。

This is their project page : https://github.com/dtmilano/AndroidViewClient 这是他们的项目页面: https : //github.com/dtmilano/AndroidViewClient

This tutorial helped me set up AndroidViewClient : https://www.darpandodiya.com/code/setup-androidviewclient-windows/ 本教程帮助我设置了AndroidViewClient: https ://www.darpandodiya.com/code/setup-androidviewclient-windows/

  1. Using this adb command : 使用此adb命令:

This command saves the UI Heirarchy XML in the device's sdcard. 此命令将UI继承XML保存在设备的sdcard中。 adb exec-out uiautomator dump

This gives the result in the console itself. 这样就可以在控制台中获得结果。 adb exec-out uiautomator dump /dev/tty

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM