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

2 posts, 0 answers
  1. Sandeepana
    Sandeepana avatar
    2 posts
    Member since:
    Feb 2013

    Posted 15 Feb 2013 Link to this post

    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..


     
  2. Boyan Boev
    Admin
    Boyan Boev avatar
    1072 posts

    Posted 15 Feb 2013 Link to this post

    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
Back to Top