我一直在玩弄AndroidViewClient了一段时间,但我不明白为什么在运行dump.py示例时此扩展程序将不显示视图的ID。我的设备高于API lvl16。可能是什么问题?
我得到这样的输出,但我又不知道为什么它不能告诉视图的名称...
android.widget.FrameLayout id/no_id/1
android.widget.LinearLayout id/no_id/2
android.widget.FrameLayout id/no_id/3
android.widget.RelativeLayout id/no_id/4
android.widget.Button id/no_id/5 New Jersey
android.widget.Button id/no_id/6 New York
android.widget.Button id/no_id/7 New Castle
android.widget.Button id/no_id/8 New Berg
android.widget.Button id/no_id/9 New Class
错误:
C:\Users\EGHDK\android-sdk\tools>monkeyrunner C:\AndroidViewClient-master\Andro
idViewClient-master\AndroidViewClient\examples\dump.py
130428 20:11:28.636:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions
] Script terminated due to an exception
130428 20:11:28.636:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions
]Traceback (most recent call last):
File "C:\AndroidViewClient-master\AndroidViewClient-master\AndroidViewClient\e
xamples\dump.py", line 87, in <module>
vc = ViewClient(*ViewClient.connectToDeviceOrExit(**kwargs1), **kwargs2)
File "C:\AndroidViewClient-master\AndroidViewClient-master\AndroidViewClient\s
rc\com\dtmilano\android\viewclient.py", line 935, in __init__
adb = ViewClient.__obtainAdbPath()
File "C:\AndroidViewClient-master\AndroidViewClient-master\AndroidViewClient\s
rc\com\dtmilano\android\viewclient.py", line 1075, in _ViewClient__obtainAdbPath
raise Exception('adb="%s" is not executable. Did you forget to set ANDROID_H
OME in the environment?' % adb)
Exception: adb="adb.exe" is not executable. Did you forget to set ANDROID_HOME i
n the environment?
130428 20:11:28.636:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions
] at org.python.core.PyException.doRaise(PyException.java:219)
130428 20:11:28.636:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions
] at org.python.core.Py.makeException(Py.java:1159)
130428 20:11:28.636:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions
] at org.python.core.Py.makeException(Py.java:1163)
130428 20:11:28.636:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions
] at org.python.core.Py.makeException(Py.java:1167)
130428 20:11:28.636:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions
] at com.dtmilano.android.viewclient$py._ViewClient__obtainAdbPath$56(C:\A
ndroidViewClient-master\AndroidViewClient-master\AndroidViewClient\src\com\dtmil
ano\android\viewclient.py:1075)
130428 20:11:28.636:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions
] at com.dtmilano.android.viewclient$py.call_function(C:\AndroidViewClient
-master\AndroidViewClient-master\AndroidViewClient\src\com\dtmilano\android\view
client.py)
130428 20:11:28.636:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions
] at org.python.core.PyTableCode.call(PyTableCode.java:165)
130428 20:11:28.636:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions
] at org.python.core.PyBaseCode.call(PyBaseCode.java:117)
130428 20:11:28.636:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions
] at org.python.core.PyFunction.__call__(PyFunction.java:307)
130428 20:11:28.636:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions
] at com.dtmilano.android.viewclient$py.__init__$54(C:\AndroidViewClient-m
aster\AndroidViewClient-master\AndroidViewClient\src\com\dtmilano\android\viewcl
ient.py:1020)
130428 20:11:28.636:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions
] at com.dtmilano.android.viewclient$py.call_function(C:\AndroidViewClient
-master\AndroidViewClient-master\AndroidViewClient\src\com\dtmilano\android\view
client.py)
130428 20:11:28.636:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions
] at org.python.core.PyTableCode.call(PyTableCode.java:165)
130428 20:11:28.636:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions
] at org.python.core.PyBaseCode.call(PyBaseCode.java:297)
130428 20:11:28.636:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions
] at org.python.core.PyBaseCode.call(PyBaseCode.java:191)
130428 20:11:28.636:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions
] at org.python.core.PyFunction.__call__(PyFunction.java:385)
130428 20:11:28.636:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions
] at org.python.core.PyFunction.__call__(PyFunction.java:380)
130428 20:11:28.636:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions
] at org.python.core.PyInstance.__init__(PyInstance.java:120)
130428 20:11:28.636:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions
] at org.python.core.PyClass.__call__(PyClass.java:194)
130428 20:11:28.636:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions
] at org.python.core.PyObject._callextra(PyObject.java:537)
130428 20:11:28.636:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions
] at org.python.pycode._pyx0.f$0(C:\AndroidViewClient-master\AndroidViewCl
ient-master\AndroidViewClient\examples\dump.py:89)
130428 20:11:28.636:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions
] at org.python.pycode._pyx0.call_function(C:\AndroidViewClient-master\And
roidViewClient-master\AndroidViewClient\examples\dump.py)
130428 20:11:28.636:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions
] at org.python.core.PyTableCode.call(PyTableCode.java:165)
130428 20:11:28.636:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions
] at org.python.core.PyCode.call(PyCode.java:18)
130428 20:11:28.636:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions
] at org.python.core.Py.runCode(Py.java:1197)
130428 20:11:28.636:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions
] at org.python.core.__builtin__.execfile_flags(__builtin__.java:538)
130428 20:11:28.636:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions
] at org.python.util.PythonInterpreter.execfile(PythonInterpreter.java:156
)
130428 20:11:28.636:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions
] at com.android.monkeyrunner.ScriptRunner.run(ScriptRunner.java:116)
130428 20:11:28.636:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions
] at com.android.monkeyrunner.MonkeyRunnerStarter.run(MonkeyRunnerStarter.
java:77)
130428 20:11:28.636:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions
] at com.android.monkeyrunner.MonkeyRunnerStarter.main(MonkeyRunnerStarter
.java:189)
最佳答案
如果设备的API级别> = 16,则AndroidViewClient使用的默认后端是UiAutomator,它不显示ID。为了提供额外的帮助,AndroidViewClient会为视图分配唯一的ID,这就是您的案例中显示的dump.py
。
您可以通过为dump.py
提供相应的命令行选项来强制ViewServer后端:
$ dmup.py --force-view-server-use
您将获得View ID。