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.
Asked
Active
Viewed 1,132 times
2

CloudyMarble
- 36,908
- 70
- 97
- 130

user1344022
- 193
- 2
- 3
- 10
1 Answers
1
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);
}
}
}

Alexey Romanov
- 167,066
- 35
- 309
- 487
-
Hi Alexey Thanks for the reply, i want to tell you that i am new to Eclipse Programming. So i have few doubts about the answer you have given. As i am running my Eclipse in the SWTbot context so How am i going to get the Object of the Control class and the Composite object. Can you please elaborate your answer that i can understand.OR send some Example of that. Thanks In advance !!!! – user1344022 Feb 06 '13 at 06:55
-
To find the controls you need in SWTBot, use http://download.eclipse.org/technology/swtbot/galileo/dev-build/apidocs/org/eclipse/swtbot/swt/finder/package-summary.html – Alexey Romanov Feb 06 '13 at 07:03
-
Alexey, i have written some thing like this but No luck so Far. SWTBot botFinder = new SWTBot(); Matcher
matcher = allOf(widgetOfType(Composite.class),inGroup("Product")); Composite c = (Composite) botFinder.widget(matcher); allTExt = getContainedText((Control) c, new ArrayList – user1344022 Feb 06 '13 at 08:34()); -
I have ScrolledComosit in Location /Shell/-1//Shell/-1//Composite/0//Composite/0//Composite/0//Composite/1//Composite/2//ScrolledComposite/1//Composite/0//Group/0 "And I want to Pass the Object of the ScrolledComposite to the Control and then we can use the Method you have given. – user1344022 Feb 06 '13 at 10:29