How to find FrameworkElement by tag name

6 posts, 0 answers
  1. Yogesh
    Yogesh avatar
    11 posts
    Member since:
    Jan 2011

    Posted 31 Jan 2014 Link to this post

    I am using Silverlight automtation testing using WebAII

    In my applet there is FrameworkElement Border with Tag as "news"

    How can I find this element ?

    I tried following but does not work. Any idea ?

                manager.ActiveBrowser.NavigateTo("https://myserver.com");
                SilverlightApp app = manager.ActiveBrowser.SilverlightApps()[0];
                FrameworkElement my  = app.Find.ByExpression(new XamlFindExpression("Tag=news"));
  2. Boyan Boev
    Admin
    Boyan Boev avatar
    1039 posts

    Posted 31 Jan 2014 Link to this post

    Hi Yogesh,

    Thank you for contacting us.

    Please try out with this code:

    manager.ActiveBrowser.NavigateTo("https://myserver.com");
    SilverlightApp app = manager.ActiveBrowser.SilverlightApps()[0];
    FrameworkElement my  = app.Find.ByExpression(new XamlFindExpression("XamlTag=news"));

    Let me know if this helps.

    Regards,
    Boyan Boev
    Telerik
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
  3. Yogesh
    Yogesh avatar
    11 posts
    Member since:
    Jan 2011

    Posted 03 Feb 2014 Link to this post


      
    According to you
    FrameworkElement my  = app.Find.ByExpression(new XamlFindExpression("XamlTag=news"));

    will work for finding news Framework Element for following block

    <news>
       <image></image>
       <textblock></textblock>
    </news>




    What I want is to find a FrameworkElement which has Tag specified. For example, I want to find Framwork element textblock from following which has tag='johnsmith'. 

    <border>
       <image></image>
       <textblock tag='johnsmith'></textblock>
    </border>










  4. Boyan Boev
    Admin
    Boyan Boev avatar
    1039 posts

    Posted 06 Feb 2014 Link to this post

    Hi Yogesh,

    Then your code should look like:

    IList<TextBlock> list = app.Find.AllByType<TextBlock>();
    foreach(TextBlock item in list)
     {
    if(item.GetProperty(new AutomationProperty("Tag", typeof(string))).ToString()=="johnsmith")
    {
         item.User.Click();
    }
    }

    This will find all TextBlockes (like in your case) and clicks on the first with Tag "johnsmith".

    Hope that helps.

    Regards,
    Boyan Boev
    Telerik
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
  5. Yogesh
    Yogesh avatar
    11 posts
    Member since:
    Jan 2011

    Posted 12 Feb 2014 Link to this post

    Thank you very much Boyan Boev,

    It worked for me. Here sharing function I have written

    public static T FindByTag<T>(SilverlightApp app, String propertyValue) where T : FrameworkElement, new()
    {
        IList<T> list = app.Find.AllByType<T>();
        T foundItem = new T();
        foreach (T item in list)
        {
            try
            {
                if (item.GetProperty(new AutomationProperty("Tag", typeof(string))).ToString() == propertyValue)
                {
                    foundItem = item;
                    break;
                }
            }
            catch
            {
                continue;
            }
        }
        return foundItem;
    }
  6. Boyan Boev
    Admin
    Boyan Boev avatar
    1039 posts

    Posted 12 Feb 2014 Link to this post

    Hello Yogesh,

    I am really happy to hear that.

    If you need further help, please let us know.

    Regards,
    Boyan Boev
    Telerik
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
Back to Top