我有一个 monkeyrunner 脚本,它试图获取有关其中一个 View 的一些信息,如下所示:
v = d.getViewById('id/search_progress_bar')
print dir(v)
for i in range(10):
print 'about to call v.getLocation'
print v.getLocation()
m.sleep(1)
这是 dir(v) 步骤的输出:
['__class__', '__delattr__', '__doc__', '__getattribute__', '__hash__', '__init__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__str__', 'getAccessibilityIds', 'getChecked', 'getChildren', 'getEnabled', 'getFocused', 'getLocation', 'getParent', 'getSelected', 'getText', 'getViewClass', 'setFocused', 'setSelected']
但是,当我尝试使用 v.getLocation() 方法时,我立即得到下面的异常。
121024 16:30:26.373:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions] Script terminated due to an exception
121024 16:30:26.373:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]Traceback (most recent call last):
File "/Users/swolfe/svn/jython/progress_bar_testing.py", line 20, in <module>
print v.getLocation()
at com.android.chimpchat.ChimpManager.queryView(ChimpManager.java:414)
at com.android.chimpchat.core.ChimpView.queryView(ChimpView.java:52)
at com.android.chimpchat.core.ChimpView.getLocation(ChimpView.java:64)
at com.android.monkeyrunner.MonkeyView.getLocation(MonkeyView.java:81)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
com.android.chimpchat.core.ChimpException: com.android.chimpchat.core.ChimpException: No accessibility event has occured yet
有人熟悉 ChimpChat 吗?我不明白这是 MonkeyRunner 的一些核心代码。 accessibility 和 MonkeyRunner 之间是什么关系,为什么它会提示 accessibility event 还没有发生?我是否需要启动某种辅助功能或检测服务?
谢谢。
最佳答案
你是对的。它不起作用。但是你可以使用 AndroidViewClient ,这确实有效,脚本将是:
vc = ViewClient(d, serialno)
v = vc.findViewByIdOrRaise('id/search_progress_bar')
print dir(v)
for i in range(10):
print 'about to call v.getCoords'
print v.getCoords()
m.sleep(1)
并打印类似的东西
['_View__dumpWindowsInformation', '_View__obtainPxPy', '_View__obtainStatusBarDimensionsIfVisible', '_View__obtainVwVh', '_View__obtainVxVy', '__call__', '__doc__', '__getattr__', '__getitem__', '__init__', '__module__', '__smallStr__', '__str__', '__tinyStr__', 'add', 'allPossibleNamesWithColon', 'build', 'children', 'currentFocus', 'device', 'factory', 'getCenter', 'getClass', 'getCoords', 'getHeight', 'getId', 'getParent', 'getPositionAndSize', 'getText', 'getUniqueId', 'getVisibility', 'getWidth', 'getX', 'getXY', 'getY', 'intersection', 'map', 'parent', 'touch', 'windows']
about to call v.getCoords
((0, 157), (480, 229))
about to call v.getCords
((0, 157), (480, 229))
...
我怀疑你的 Intent 是什么,除非你希望你的观点发生变化。
关于android - monkeyrunner - 尝试使用 view.getLocation() 时出现 ChimpException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13059512/