缘由

uiautomator2 中 uiobject2 及 uiobject 对象均未提供获取 password 属性值的方法:isPassword

修复方法

修改 UiObject2Element

public boolean getBoolAttribute(final String attr)
        throws UiObjectNotFoundException, NoAttributeFoundException, UiAutomator2Exception {
    boolean res;
    if ("enabled".equals(attr)) {
        res = element.isEnabled();
    } else if ("checkable".equals(attr)) {
        res = element.isCheckable();
    } else if ("checked".equals(attr)) {
        res = element.isChecked();
    } else if ("clickable".equals(attr)) {
        res = element.isClickable();
    } else if ("focusable".equals(attr)) {
        res = element.isFocusable();
    } else if ("focused".equals(attr)) {
        res = element.isFocused();
    } else if ("longClickable".equals(attr)) {
        res = element.isLongClickable();
    } else if ("scrollable".equals(attr)) {
        res = element.isScrollable();
    } else if ("selected".equals(attr)) {
        res = element.isSelected();
    } else if ("displayed".equals(attr)) {
        res = invoke(method(UiObject2.class, "getAccessibilityNodeInfo"), element) != null ? true : false;
    } else if ("password".equals(attr)) { //新增password属性值获取代码
        res = AccessibilityNodeInfoGetter.fromUiObject(element).isPassword(); //通过源码提供的反射调用机制获取节点,再获取其属性
    }  else {
        throw new NoAttributeFoundException(attr);
    }
    return res;
}

重新打包即可


↙↙↙阅读原文可查看相关链接,并与作者交流