This is a migrated thread and some comments may be shown as answers.

Find a label by name is giving error

6 Answers 37 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Lim
Top achievements
Rank 1
Lim asked on 08 Sep 2010, 11:15 AM
Hi there. I have a label in my SL control.  When I try to search for it by name I get an error that doesn't seem to make sense.

Running the following code:
Assert.That(MyControl.Find.ByName("valueTextBlock").As<TextBlock>().Text, Is.EqualTo("Football"));

I get: 
System.ArgumentException : The control type 'ArtOfTest.WebAii.Silverlight.UI.TextBlock' does not match the xaml tag 'label'


Is this right??

I manage to find the label by doing
Assert.That(MyControl.Find.AllByType<TextBlock>()[1].Text, Is.EqualTo("Football"));

So if the above search worked why would the first one fail? If someone could explain this to me that would be great.  I wonder if it's a bug or a coding error.

Thanks 

6 Answers, 1 is accepted

Sort by
0
Konstantin Petkov
Telerik team
answered on 08 Sep 2010, 12:19 PM
Hello Lim,

The Label and TextBlock are different controls in Silverlight. I assume the first search returns the Label with that name which you cannot cast to TextBlock.

Can you please check what you get as name from that TextBlock? Try

MyControl.Find.AllByType<TextBlock>()[1].Name

since you cannot have two controls with the same names in a Silverlight application (the project simply does not compile).

Best wishes,
Konstantin Petkov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Lim
Top achievements
Rank 1
answered on 08 Sep 2010, 12:42 PM
Hi Konstantin 
I tried that and it returned an String.Empty.
0
Konstantin Petkov
Telerik team
answered on 08 Sep 2010, 12:49 PM
Hello Lim,

Yes, that explains it. These Label and TextBlock are separate elements and the Label has the name you search for.

All the best,
Konstantin Petkov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Lim
Top achievements
Rank 1
answered on 08 Sep 2010, 12:58 PM
But WebAii doesn't have a Label type so how can I get the content of the label?  I tried not casting it and getting TextContent but that returned String.Empty as well.  And also why can I find it if I use Find.AllByType<TextBlock>()[1]?

I also downloaded a trial WebUI to check this out and it looks like even WebUI identifies it as a textblock.
0
Konstantin Petkov
Telerik team
answered on 08 Sep 2010, 01:31 PM
Hello Lim,

You can use the common ContentControl the Label in Silverlight inherits from. Then just use a Find call to locate the TextBlock element within and check its Text. I have attached an image of the Label control visual tree.

Sincerely yours,
Konstantin Petkov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
adhy
Top achievements
Rank 1
answered on 02 Oct 2015, 02:55 AM

I am very new tioUI automation. I had a similar issue with label.your solution solved my issue with label. But same element not found is happening for datagrid ,hyperlinkbutton. it is correctly detecting button elements.Please advice.

heare is the line related to hyperlinkbutton

app.Find.ByName<ArtOfTest.WebAii.Silverlight.UI.HyperlinkButton>("Link1").User.Click();

Tags
General Discussions
Asked by
Lim
Top achievements
Rank 1
Answers by
Konstantin Petkov
Telerik team
Lim
Top achievements
Rank 1
adhy
Top achievements
Rank 1
Share this question
or