Selecting element in group of buttons by text

2 posts, 0 answers
  1. Andy
    Andy avatar
    1 posts
    Member since:
    Nov 2014

    Posted 05 Nov 2014 Link to this post


    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;

  2. Cody
    Cody avatar
    3354 posts

    Posted 07 Nov 2014 Link to this post

    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.

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