模拟点击用于查找H5页面节点的递归算法

2020-06-23  本文已影响0人  郑伟1

哈哈哈哈哈 老夫查了好多都没好用的 灵机一动 简简单单找到了那个节点 他最恶心的是有的节点文字你是获取不到的 然后我也不知道哪个方法能返回回来 搞了好多个一起打印 总算让老子找到了 记录下来 以后继续用

/**
     * 用于递归查找h5节点的
     * @param nodeInfo 这个就是查节点的第一个入口了  建议越外层越好
     * @param path 这个是用来画路径的  剩的你找到了对象  找不到他的位置
     */
    private void searchClickableView(AccessibilityNodeInfo nodeInfo, String path) {
        if (nodeInfo != null) {
            for (int i = 0; i < nodeInfo.getChildCount(); i++) {
                String pathStr = path + "," + i;
                AccessibilityNodeInfo child = nodeInfo.getChild(i);
                if (child == null) continue;
                if (child.isClickable()) {
                    performViewClick(child);
                    LogUtil.show("getViewIdResourceName:" + child.getViewIdResourceName()
                            + ",getContentDescription:" + child.getContentDescription()
                            + ",getClassName:" + child.getClassName()
                            + ",getText:" + child.getText()
                            + ",path:" + pathStr
                    );
                    continue;
                }
                if (child.getChildCount() > 0) {
                    searchClickableView(child, pathStr);
                }
            }
        }
        LogUtil.show("path:" + path);
    }
上一篇下一篇

猜你喜欢

热点阅读