我正在运行AndroidViewClient并且能够转储完整的层次结构,但是当我尝试getXY()或touch()时,事情就失败了。即使是Get Current Focused Window Name using AndroidViewClient的解决方案也会给我一个错误。
kwargs1 = {'verbose': True, 'ignoresecuredevice': True}
kwargs2 = {'startviewserver': True, 'forceviewserveruse': True,
'autodump': False, 'ignoreuiautomatorkilled': True}
device, serialno = ViewClient.connectToDeviceOrExit(**kwargs1)
vc = ViewClient(device, serialno, **kwargs2)
view = vc.dump(window='-1')
widget = vc.findViewByIdOrRaise("id/no_id/5")
widget.useUiAutomator = False
print widget
# Up until here runs no problem.
print widget.getXY() # fails.
widget.touch() # also fails.
我的堆栈跟踪类似于:
print widget.getXY()
文件" /usr/local/lib/python2.7/dist-packages/androidviewclient-11.5.3-py2.7.egg/com/dtmilano/android/viewclient.py" ;,第680行,在getXY中 (wvx,wvy)= self .__ dumpWindowsInformation(debug = debug)
File" /usr/local/lib/python2.7/dist-packages/androidviewclient-11.5.3-py2.7.egg/com/dtmilano/android/viewclient.py" ;,第798行,在__dumpWindowsInformation中
dww = self.device.shell('dumpsys window windows')
文件" /usr/local/lib/python2.7/dist-packages/androidviewclient-11.5.3-py2.7.egg/com/dtmilano/android/adb/adbclient.py",第377行,在shell中
self.__send('shell:%s' % cmd, checkok=True, reconnect=False)
文件" /usr/local/lib/python2.7/dist-packages/androidviewclient-11.5.3-py2.7.egg/com/dtmilano/android/adb/adbclient.py",第243行,在__send
self.__checkOk()
文件" /usr/local/lib/python2.7/dist-packages/androidviewclient-11.5.3-py2.7.egg/com/dtmilano/android/adb/adbclient.py",第286行,在__checkOk
raise RuntimeError("ERROR: %s %s" % (repr(recv), error))
RuntimeError:错误:''
有什么想法吗?
答案 0 :(得分:0)
widget = vc.findViewByIdOrRaise("id/no_id/5")
widget.useUiAutomator = False
widget.getXY()
x = (str)widget.windows[widget.currentFocus]
print x
上面的代码将获取显示活动名称以及屏幕的高度和宽度,如果你只想要高度和宽度参考下面的一个
h = device._AdbClient__getDisplayHeight("")
w = device._AdbClient__getDisplayWidth("")
print (str)(h)
print (str)(w)