fun count(obj: Selector): Int { return if (obj.getMask() and Selector.MASK_INSTANCE > 0) { if (device.findObject(obj.toUiSelector()).exists()) 1 else 0 } else { var sel: UiSelector = obj.toUiSelector() if (!device.findObject(sel).exists()) return 0 var low = 1 var high = 2 sel = sel.instance(high - 1) while (device.findObject(sel).exists()) { low = high high = high * 2 sel = sel.instance(high - 1) } while (high > low + 1) { val mid = (low + high) / 2 sel = sel.instance(mid - 1) if (device.findObject(sel).exists()) low = mid else high = mid } low } }
Get the count of the UiObject instances by the selector