简体   繁体   English

如何从AccessibilityNodeInfo中的所有子节点获取文本

[英]how to get text from all the child nodes in AccessibilityNodeInfo

I'm trying to read the text from all the child nodes of an AccessiblityNodeInfo. 我正在尝试从AccessiblityNodeInfo的所有子节点读取文本。

I tried getting AccessiblityNodeInfo.getParent() and AccessibilityNodeInfo.getChildCount() 我尝试获取AccessiblityNodeInfo.getParent()AccessibilityNodeInfo.getChildCount()

for(int i=0; i<accessibilityNodeInfo.getChildCount();i++){
accessibilityNodeInfo.getChild(i).getText();
}

Accessed the child nodes as mentioned above to get the text from the child nodes. 如上所述访问子节点以从子节点获取文本。 but it is not providing the all the text on the screen. 但它没有提供屏幕上的所有文本。

Can anyone suggest me what to do get the text? 谁能建议我该怎么做?

private List<CharSequence> getAllChildNodeText(AccessibilityNodeInfoCompat infoCompat) {
    List<CharSequence> contents = new ArrayList<>();
    if (infoCompat == null)
        return contents;
    if (infoCompat.getContentDescription() != null) {
        contents.add(infoCompat.getContentDescription().toString().isEmpty() ? "unlabelled" : infoCompat.getContentDescription());
    } else if (infoCompat.getText() != null) {
        contents.add(infoCompat.getText().toString().isEmpty() ? "unlabelled" : infoCompat.getText());
    } else {
        getTextInChildren(infoCompat, contents);
    }
    if (infoCompat.isClickable()) {
        if (infoCompat.getClassName().toString().contains(Button.class.getSimpleName())) {
            if (contents.size() == 0) {
                contents.add("Unlabelled button");
            } else {
                contents.add("button");
            }
        }
        contents.add("Double tap to activate");
    }
    return contents;
}


private void getTextInChildren(AccessibilityNodeInfoCompat nodeInfoCompat, List<CharSequence> contents) {
    if (nodeInfoCompat == null)
        return;
    if (!nodeInfoCompat.isScrollable()) {
        if (nodeInfoCompat.getContentDescription() != null) {
            contents.add(nodeInfoCompat.getContentDescription());
        } else if (nodeInfoCompat.getText() != null) {
            contents.add(nodeInfoCompat.getText());
        }
        if (nodeInfoCompat.getChildCount() > 0) {
            for (int i = 0; i < nodeInfoCompat.getChildCount(); i++) {
                if (nodeInfoCompat.getChild(i) != null) {
                    getTextInChildren(nodeInfoCompat.getChild(i), contents);
                }
            }
        }
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从firebase数据库中获取所有子节点? - how to get all child nodes from firebase database? 如何从AccessibilityDelegate的AccessibilityNodeInfo中的视图中提取文本? - How to extract the text from Views in AccessibilityDelegate's AccessibilityNodeInfo? 如何查找所有子节点的文本 - How to find text of all child nodes 如何在 Selenium WebElement 中获取元素的所有子节点,包括文本节点? - How do I get all child nodes of an element , including text ones, in Selenium WebElement? 如何获取列表中所有子元素的文本 - How to get the text of all child elements in a list 获取节点 XML Java 的所有子节点 - Get all child nodes of a node XML Java Selenium-如何从多个子节点中的一个子(文本)节点检索文本 - Selenium - How to retrieve text from a child (text) node among multiple child nodes 如何从我插入到 Listview 的数据中获取子节点? - How to get the child nodes from the data I inserted into Listview? 如何从子节点的值中获取父节点的名称? - How to get the name of the parent node from the values of child nodes? 如何从Firebase中删除一个子节点而不删除所有子节点 - How to Remove one child node from firebase with out deleting all child nodes
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM