Get Current Focused Window Name using AndroidViewClient

妖精的绣舞 提交于 2020-01-21 10:25:22

问题


I am using AndroidViewClient for testing my android application. I need to access name of current focused window. How can I get it?


回答1:


It's a bit tricky but can be done. The information about the windows and focus is internally maintained by the Views under some conditions.

You may try something like this (choose any view you have):

...
vc = ViewClient(device, serialno, **kwargs2)
vc.dump(window='-1')
no_id1 = vc.findViewByIdOrRaise("id/no_id/1")
no_id1.useUiAutomator = False    # this forces getting windows info
no_id1.getXY()                   # this gets windows info
print no_id1.windows[no_id1.currentFocus] 


来源:https://stackoverflow.com/questions/24089937/get-current-focused-window-name-using-androidviewclient

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!