Radio button labels

3 posts, 1 answers
  1. Cheryl
    Cheryl avatar
    45 posts
    Member since:
    Jul 2006

    Posted 10 Apr 2012 Link to this post

    Hello

    In code, how do I refer to a radio button's label in order to check it against data?

    There doesn't seem to be an obvious text property for the actual HtmlInputRadioButton, and if I add the label itself to the Elements the find logic refers to the content.  I can't use this as the content is dynamic.

    Any suggestions?


    Thanks
    Cheryl
  2. Answer
    Plamen
    Admin
    Plamen avatar
    8 posts

    Posted 11 Apr 2012 Link to this post

    Hi Cheryl,

    In order to get the text from the label, you need to find the row that contains the label first. Then you can easily check the radio button located in the same row. Here's a sample coded step against this Telerik demo site and a video demonstrating how it works:
    public void WebTest_CodedStep()
    {
        HtmlTable table = Find.ById<HtmlTable>("RadioButtonList1");
        Assert.IsNotNull(table);
     
        foreach (HtmlTableRow row in table.AllRows)
        {
            if (row.InnerText == Data["Col1"].ToString())
            {
                HtmlInputRadioButton button = row.Find.ByExpression<HtmlInputRadioButton>("tagname=input");
                button.Check(true, true);
            }
        }
    }

    If the coded step above doesn't work in your case, please provide access to your application or point me to a publicly accessible application similar to yours. I'll be glad to assist you in writing the code.

    All the best,
    Plamen
    the Telerik team
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
  3. Cheryl
    Cheryl avatar
    45 posts
    Member since:
    Jul 2006

    Posted 23 Apr 2012 Link to this post

    Great thanks.
Back to Top