xiaocong/android-uiautomator-server

Maybe it's not necessary to search through both BySelector and UiSelector.

Opened this issue · 0 comments

After reading the code I found that we will search for UI object firstly by BySelector and later by UiSelector if search by BySelector failed when conducting click or something similar:

    public boolean click(Selector obj) throws UiObjectNotFoundException {
        if (obj.toUiObject2() == null) {
            return device.findObject(obj.toUiSelector()).click();
        } else {
            obj.toUiObject2().click();
            return true;
        }
    }

The source of UiAutomator shows that both two ways will finally invoke UiAutomation.getRootInActiveWindow(). So UiSelector can't do more than BySelector. BySelector even supports multi-window search while UiSelector doesn't. The only reason to use UiSelector is that it will delay the search operation. Maybe it's useful for a Java instrumental test, but it seems meaningless to hold a reference of a remote object in a python script. Even worse, searching by UiSelector is asynchronous and will waste time to wait for timeout.
So I suggest to use BySelector only when doing search. Would you accept my pull request if I made one to fix it?