Hello everybody,
I encountered an issue during automation testing like that:
There is a custome control with the type of "SelectableTextBlock" in our silverlight app, the text of which is "jkljljkljljl". In my test code, I need to retrieve the value of the text, but the valued is empty after extecute , so I need your help. My test code is below:
Attached image is the custome control and the value of it's text.
Thanks!!
Lucia
I encountered an issue during automation testing like that:
There is a custome control with the type of "SelectableTextBlock" in our silverlight app, the text of which is "jkljljkljljl". In my test code, I need to retrieve the value of the text, but the valued is empty after extecute , so I need your help. My test code is below:
FrameworkElement tbContent = lstBBSReplyItem[i].Find.ByType("SelectableTextBlock");
console.WriteLine(tbContent.TextLiteralContent);
Attached image is the custome control and the value of it's text.
Thanks!!
Lucia
6 Answers, 1 is accepted
0
Hi Lucia,
First, please ensure that the element is successfully found. You can do that by using the Assert method. Then you can try to fetch the text using the Text property of the FrameworkElement. This will search for the first textblock text contained in the FrameworkElement. Here's the code:
Hope this helps!
Regards,
Plamen
the Telerik team
First, please ensure that the element is successfully found. You can do that by using the Assert method. Then you can try to fetch the text using the Text property of the FrameworkElement. This will search for the first textblock text contained in the FrameworkElement. Here's the code:
FrameworkElement tbContent = lstBBSReplyItem[i].Find.ByType(
"SelectableTextBlock"
);
Assert.IsNotNull(tbContent);
console.WriteLine(tbContent.Text);
Hope this helps!
Regards,
Plamen
the Telerik team
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
Test Studio Trainings
0
lucia
Top achievements
Rank 1
answered on 15 Feb 2012, 06:21 AM
Hi Plamen
I am sure the element is found. I have identified it and retrieved it's other properties except the value of Text. After transfer the element into XML and output on the console, I can not yet find the Text in the XML. So I asked you for help...Thanks!!
I am sure the element is found. I have identified it and retrieved it's other properties except the value of Text. After transfer the element into XML and output on the console, I can not yet find the Text in the XML. So I asked you for help...Thanks!!
0
Hi Lucia,
Try to cast the FrameworkElement as a TextBlock and you should be able to use the Text automation property of the TextBlock. Try it like this:
Regards,
Plamen
the Telerik team
Try to cast the FrameworkElement as a TextBlock and you should be able to use the Text automation property of the TextBlock. Try it like this:
FrameworkElement tbContent = lstBBSReplyItem.Find.ByType(
"SelectableTextBlock"
).CastAs<TextBlock>();
Console.WriteLine(tbContent.Text);
Regards,
Plamen
the Telerik team
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
Test Studio Trainings
0
lucia
Top achievements
Rank 1
answered on 16 Feb 2012, 03:13 AM
Hi Plamen,
Thanks for your help. But my prolbem is still not resolved after cast the element as textblock... :(.
Thanks for your help. But my prolbem is still not resolved after cast the element as textblock... :(.
0
Jacek Drozd
Top achievements
Rank 1
answered on 16 Feb 2012, 02:24 PM
Hi Lucia,
You can try this way:
Before executing it be sure that Your VisualTree is updated (app.RefreshVisualTree() if I remember correctly).
You can try this way:
AutomationProperty textProperty = new AutomationProperty("Text", typeof(string)); //if displayed text is in other property then change first argument
yourFoundControl.GetProperty(_textProperty, string.Empty).ToString();
Before executing it be sure that Your VisualTree is updated (app.RefreshVisualTree() if I remember correctly).
0
lucia
Top achievements
Rank 1
answered on 17 Feb 2012, 02:03 AM
Great!! The problem is resolved by the way recommended by Jacek. Thank all of you for your help!!