获取使用AndroidViewClient当前焦点窗口名称 [英] Get Current Focused Window Name using AndroidViewClient

查看:592
本文介绍了获取使用AndroidViewClient当前焦点窗口名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用AndroidViewClient测试我的Andr​​oid应用程序。我需要访问当前焦点窗口的名称。我怎样才能得到它呢?

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

推荐答案

这是一个有点棘手,但可以做到的。有关Windows和焦点的信息在内部被一定条件下的视图中得以保持。

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] 

这篇关于获取使用AndroidViewClient当前焦点窗口名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆