Find a label by name is giving error

7 posts, 0 answers
  1. Lim
    Lim avatar
    16 posts
    Member since:
    Aug 2010

    Posted 08 Sep 2010 Link to this post

    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 
  2. Konstantin Petkov
    Admin
    Konstantin Petkov avatar
    1911 posts

    Posted 08 Sep 2010 Link to this post

    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
  3. Lim
    Lim avatar
    16 posts
    Member since:
    Aug 2010

    Posted 08 Sep 2010 Link to this post

    Hi Konstantin 
    I tried that and it returned an String.Empty.
  4. Konstantin Petkov
    Admin
    Konstantin Petkov avatar
    1911 posts

    Posted 08 Sep 2010 Link to this post

    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
  5. Lim
    Lim avatar
    16 posts
    Member since:
    Aug 2010

    Posted 08 Sep 2010 Link to this post

    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.
  6. Konstantin Petkov
    Admin
    Konstantin Petkov avatar
    1911 posts

    Posted 08 Sep 2010 Link to this post

    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
  7. adhy
    adhy avatar
    5 posts
    Member since:
    Sep 2015

    Posted 01 Oct 2015 Link to this post

    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();

Back to Top