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

Radio button labels

2 Answers 64 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Cheryl
Top achievements
Rank 1
Cheryl asked on 11 Apr 2012, 04:54 AM
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 Answers, 1 is accepted

Sort by
0
Accepted
Plamen
Telerik team
answered on 11 Apr 2012, 05:01 PM
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
0
Cheryl
Top achievements
Rank 1
answered on 24 Apr 2012, 01:17 AM
Great thanks.
Tags
General Discussions
Asked by
Cheryl
Top achievements
Rank 1
Answers by
Plamen
Telerik team
Cheryl
Top achievements
Rank 1
Share this question
or