Skip to content

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

@Michaelbest1

Description

@Michaelbest1

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions