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

How to find FrameworkElement by tag name

5 Answers 79 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Yogesh
Top achievements
Rank 1
Yogesh asked on 31 Jan 2014, 10:29 AM
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"));

5 Answers, 1 is accepted

Sort by
0
Boyan Boev
Telerik team
answered on 31 Jan 2014, 12:52 PM
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
0
Yogesh
Top achievements
Rank 1
answered on 03 Feb 2014, 04:43 PM

  
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>










0
Boyan Boev
Telerik team
answered on 06 Feb 2014, 01:53 PM
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
0
Yogesh
Top achievements
Rank 1
answered on 12 Feb 2014, 01:17 PM
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;
}
0
Boyan Boev
Telerik team
answered on 12 Feb 2014, 02:59 PM
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
Tags
General Discussions
Asked by
Yogesh
Top achievements
Rank 1
Answers by
Boyan Boev
Telerik team
Yogesh
Top achievements
Rank 1
Share this question
or