How to validate a radio button

Discussion in 'Software' started by sandy_ajit, Nov 5, 2008.

  1. sandy_ajit

    sandy_ajit

    Joined:
    Nov 5, 2008
    Messages:
    1
    Hi,
    I am trying to write a test case to simulate a radio option using HttpUnit.

    My form looks like this:

    <form method="post">
    <table>
    <tr>
    <td>
    <input type="radio" name="wlw-radio_button_group_key:{actionForm.newNumber}" value="false"/>Existing Mobile Number
    Select a number
    <input type="hidden" name="wlw-select_key:{actionForm.selectedNumber}OldValue" value="true" />
    <select name="wlw-select_key:{actionForm.selectedNumber}">
    <option value="1231231234">1231231234</option>
    <option value="2342342345">2342342345</option></select>
    </td>

    <td>
    <input type="radio" name="wlw-radio_button_group_key:{actionForm.newNumber}" value="true" checked="checked"/>New Mobile Number
    Number
    <input type="text" name="{actionForm.areaCode}" maxlength="3" size="3" title="Area code" onkeyup="return autoTab(this, 3, event);" />
    <input type="text" name="{actionForm.firstThree}" maxlength="3" size="3" title="First 3" onkeyup="return autoTab(this, 3, event);" />
    <input type="text" name="{actionForm.lastFour}" maxlength="4" size="4" title="Last 4" onkeyup="return autoTab(this, 4, event);" />
    </td>
    </tr>
    </table>
    ...

    </form>

    and my test case looks like this;

    WebForm[] forms = response.getForms();
    WebForm form = forms[0];

    String number = phoneNumber.getArea()+phoneNumber.getThree()+phoneNumber.getFour();
    String radioGroupName = "wlw-radio_button_group_key:actionForm.newNumber}";

    String[] options = form.getOptions(radioGroupName); //this returns the labels of the radio button
    String[] optionsValues = form.getOptionValues(radioGroupName); //this returns true and false as per HttpUnit API

    for (int i = 0; i < options.length; i++) {
    if (options.equals("Existing Mobile Number")) {
    System.out.println("Existing");
    //do something
    } else {
    System.out.println("New");
    //do something
    }
    }

    For some reason, form.getOptions(radioGroupName) returns empty string. How do I decide which radio option is selected or how do I get the labels associated with the radio button

    Any advise is highly appreciated.

    Thanks.
    Sandy
    sandy_ajit, Nov 5, 2008
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?SWdvciBRdWFzaW1vZG8=?=

    Newbie, unable to validate with genuine windows XP Pro?

    =?Utf-8?B?SWdvciBRdWFzaW1vZG8=?=, Nov 5, 2005, in forum: Microsoft Certification
    Replies:
    0
    Views:
    3,261
    =?Utf-8?B?SWdvciBRdWFzaW1vZG8=?=
    Nov 5, 2005
  2. Dandy WEYN
    Replies:
    0
    Views:
    4,744
    Dandy WEYN
    Jul 2, 2003
  3. David
    Replies:
    0
    Views:
    710
    David
    Sep 14, 2003
  4. mark  mandel

    Start button Right button strange

    mark mandel, Aug 10, 2004, in forum: Computer Support
    Replies:
    1
    Views:
    493
  5. aspnetNewbie

    How do I reference a radio button in a datalist control

    aspnetNewbie, Apr 30, 2007, in forum: General Computer Support
    Replies:
    0
    Views:
    1,129
    aspnetNewbie
    Apr 30, 2007
Loading...

Share This Page