I am trying to get the Text from a Composite in Eclipse using the SWTbot API. I have Composite which contains Main Group and That Main Group Contains Child Groups.
The problem i am facing is i am not able to get the Text Inside the Composite, is there a way in Eclipse to get that Text.
I have attached the Image of my Composite, in which i want to get all the text like name,Min Version etc.
Please help, Its kind of blocker for my project. enter image description here

有帮助吗?

解决方案

Not directly, but you can do it in this way:

public getContainedText(Control c) {
    return getContainedText(c, new ArrayList<String>());
}

private getContainedText(Control c, List<String> strings) {
    if (c instanceof Label) {
        strings.add(((Label) c).getText();
    } else if (c instanceof Text) {
        strings.add(((Text) c).getText();
    }
    // and so on for other control types you want to handle
    // and for text you are interested in.
    // Or as an approximation, use reflection to check if
    // c has getText method and call it, but this will miss
    // List, Combo, etc.

    if (c instanceof Composite) {
        for (Control child : ((Composite) c).getChildren()) {
            getContainedText(child, strings);
        }
    }
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top