1

I am trying to loop through a collection of button objects in a SilverLight web page (there are 175 button objects) to find a button that has the text value = 'Airport". But I do not know how to get to the text property using WebAii (C#). Please could somebody help. Below is the code I have put together. The '????' parts are were I am stuck. Also, I am unsure of how to actually double click the element when I have found the one I am looking for, so if you could here here to it would be most appreciated.

var buttons2 =_silverlightApp.Find.AllByType<TextBlock>();         
for (int i = 0; i < buttons2.Count+ 1; i++)          
{

     if(buttons2.??????.text = "Airport")
     {
                 int elementNum = i;
                 ??????.LeftDoubleClick;
     }      

}
Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
ED209
  • 588
  • 1
  • 9
  • 26
  • You are trying to find a certain button... is there a reason you are not using [AutomationIds](http://msdn.microsoft.com/en-us/library/system.windows.automation.automationproperties.automationid%28v=vs.95%29.aspx)? – Martin Nov 05 '14 at 08:13
  • Hi. Sorry Im unfamiliar with AutomationIds. Is this related to WebAii? – ED209 Nov 05 '14 at 08:52
  • Actually Im not trying to find a a button, I am actually trying to find an element in a tree view with a a text value = 'Airport'. – ED209 Nov 05 '14 at 09:33

2 Answers2

0

I don't know if the Buttons you are displaying are created dynamically but in case it is an ordinary Button, declared somewhere in your xaml I recommend using AutomationIds.

<Button
    Content="Woohoo Airport! OMG!"
    AutomationProperties.AutomationId="AirportButton"/>

the WebAii class VisualFind offers

public FrameworkElement ByAutomationId(string id)

and you can call it on the (WebAii-)SilverlightApp or on a (WebAii-)FrameworkElement

SilverlightApp.Find.ByAutomationId("AirportButton");
FrameworkElement.Find.ByAutomationId("AirportButton");
Martin
  • 5,714
  • 2
  • 21
  • 41
  • Hi Martin. Thanks for the information. I didnt actually write the SilverLight App. I am just a poor misguided tester. but i have had a word with one of the SilverLight developers and he has told me that they dont have the 'AutomationProperties.AutomationId' property in the their Xaml. Also, most of the objects on the web site are dynamically generated, so Im thinking using 'ByAutomationId' wouldnt be the best approach for getting at specific elements. Any other advice would be much appreciated :-). – ED209 Nov 05 '14 at 10:48
0

I work for Telerik in the Test Studio and Webaii support team. I will endeavor to help you with this problem.

Let Webaii do the iterating and finding for you like this:

Button btn = _silverlightApp.Find.ByExpression(new XamlFindExpression("XamlTag=textblock","TextContent=Airport")).Parent().As();

I hope this helps.

Cody

sircody
  • 214
  • 1
  • 5
  • Hi I am getting the following Error when i try to use this code, please can you help:- "The type argument for method 'ArtOfTest.WebAii.Silverlight.FrameworkElement.As()' can not be inferred from the usage. try specifying the type arguments explicitly." – ED209 Nov 11 '14 at 15:42
  • Sorry about that. StackExchange is removing critical parts of the code: Button btn = _silverlightApp.Find.ByExpression(new XamlFindExpression("XamlTag=textblock","TextContent=Airport")).Parent< Button>().As< Button>(); Remove the spaces between < and Button. – sircody Nov 16 '14 at 22:47