I am using AndroidViewClient for testing my android application. I need to access name of current focused window. How can I get it?
Asked
Active
Viewed 990 times
1 Answers
0
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]

Diego Torres Milano
- 65,697
- 9
- 111
- 134
-
@dtmilano can you plz explain what is `device` , `serialno` and `**kwargs2` . – maddy d Mar 13 '15 at 07:39
-
Take a look at `culebra` and the generated script and you'll have a clearer idea (https://github.com/dtmilano/AndroidViewClient/wiki). – Diego Torres Milano Mar 13 '15 at 13:55
-
device is the adbclient instance. serialno is the serial number of the device (or regexp). kwargs are extra keyword args. – Diego Torres Milano Mar 13 '15 at 13:56