-
Notifications
You must be signed in to change notification settings - Fork 347
/
find-object
executable file
·33 lines (28 loc) · 1.45 KB
/
find-object
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#! /usr/bin/env python3
#
# Tries to find the object containing a "wrong" content description ...
#
from com.dtmilano.android.viewclient import ViewClient
helper = ViewClient.view_client_helper(kato=True)
# Let's assume with have Calculator on top (you can launch it if not).
# This selector has an intentional mistake, instead of "plus" in the description we say "add"
# to see if kato would be able to correct it and find the view.
body = {'checkable': False, 'checked': False, 'clazz': 'android.widget.ImageButton', 'clickable': True, 'depth': None,
'desc': 'add', 'index': None, 'instance': None, 'pkg': 'com.google.android.calculator',
'res': 'com.google.android.calculator:id/op_add', 'scrollable': False, 'text': None}
# This will restrict the search for candidates to the same pkg: 'com.google.android.calculator'
helper.kato.comply_with_pkg = True
try:
obj_ref = helper.ui_device.find_object(body=body)
print(helper.ui_object2.dump(oid=obj_ref.oid).desc)
except Exception as e:
print(f"I couldn't find any view matching selector={body}")
n = len(helper.kato.selectors)
if n:
print(f'But found other {n} potential ones.')
print('Choosing a closest selector from such potential list:')
body = next(iter(helper.kato.distances.values()))
obj_ref = helper.ui_device.find_object(body=body)
print(helper.ui_object2.dump(oid=obj_ref.oid))
else:
print('There are no potential ones either.')