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

How to Set and Get values for text boxes, check boxes, radio buttons and Labels

1 Answer 132 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Sandeepana
Top achievements
Rank 1
Sandeepana asked on 15 Feb 2013, 09:18 AM
How to Set and Get values for text boxes, check boxes, radio buttons and  Labels...

Scenario 01:-
 Need to ask very basic question. Assume in my web page there are Text boxes,Check boxes, Radio buttons and  Labels. In my code level I need to Set some values to these components. Refer the following example. I am using TestStudio Project and hope to implement code in the ''New Coded Step'' area. Please guide through code how to SET values to following fields. I do not need a Enumeration examples.
  ex: -
     TextBoxA = 'Obama'
     TextBoxB = 'Sanath'
     TextBoxC = 'Mike'   
     RadioButtonA = true
     CheckBoxA = true
     LableA = 'This is February'

Scenario 02:-
I need to GET values of above components which user is inserted.Consider this is as a different case. I am using TestStudio Project and hope to implement code in the ''New Coded Step'' area. Please guide through code how to GET values to following fields. I do not need a Enumeration examples. Please refer attached screenshot. That is the form which I need to GET values..


 

1 Answer, 1 is accepted

Sort by
0
Boyan Boev
Telerik team
answered on 15 Feb 2013, 01:56 PM
Hi Sandeepana,

Thank you for trying Test Studio.

You don't need to use code to set the values of these controls. It can be achieved with a regular recording.

I recorded a short video as a demonstration.

You can also extract the values in a variable without a code as well and use it in an another step.

Here is another video that demonstrates it.3

Check also how to Get/Set extracted value in code.

If it is really necessary to be in a code you can easily set/get their values:

//Set text of the texbox.
HtmlInputText firstName = Manager.ActiveBrowser.Find.ById<HtmlInputText>("fname");
firstName.Text="CodedTest";
             
//Select radio button.
HtmlInputRadioButton rad = Manager.ActiveBrowser.Find.ById<HtmlInputRadioButton>("male");
rad.Check(true, true);
             
//Select checkbox
HtmlInputCheckBox check = Manager.ActiveBrowser.Find.ById<HtmlInputCheckBox>("check");
check.Check(true, true);
             
//get the text of the textbox
HtmlInputText firstNameText = Manager.ActiveBrowser.Find.ById<HtmlInputText>("fname");
string text = firstName.Text;
Log.WriteLine(text);

This code is against a simple HTML application which is attached in this post.

I recorded another short video to demonstrate it.

Hope this helps.

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