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

Selecting element in group of buttons by text

1 Answer 29 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Andy
Top achievements
Rank 1
Andy asked on 05 Nov 2014, 08:04 AM
Hi,

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;
     }      

}

1 Answer, 1 is accepted

Sort by
0
Cody
Telerik team
answered on 07 Nov 2014, 10:52 PM
Hi Andy,

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.


Regards,
Cody
Telerik
 
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
 
Tags
General Discussions
Asked by
Andy
Top achievements
Rank 1
Answers by
Cody
Telerik team
Share this question
or