Menu

#176 asText on HtmlRadioButtonInput and HtmlCheckBoxInput

closed
None
5
2012-10-21
2004-12-11
No

The asText() function on HtmlCheckBoxInput and
HtmlRadioButtonInput returns the value of the "value"
attribute. This is not very useful. I will upload a patch
that changes the behavor of these two classes to
return "true" or "false" dependent on whether the control
is checked or unchecked.

Discussion

  • Mike Bresnahan

    Mike Bresnahan - 2004-12-11

    Test Case

     
  • Mike Bresnahan

    Mike Bresnahan - 2004-12-11

    Fix

     
  • Mike Bresnahan

    Mike Bresnahan - 2004-12-16

    Logged In: YES
    user_id=263077

    The reason I have submitted this patch is that I often use
    HtmlUnit in combination with DBUnit (dbunit.sf.net) to test
    web applications that are also database applications. In
    particular I use DBUnit and HtmlUnit in combination to
    compare the data displayed in a HTML table to an expected
    dataset. To make this happen I need to convert each cell in
    the HTML table into a scalar value. This can be challenging if
    the cell contains multiple elements (e.g. ,

    ,

    ,
    etc.), extra whitespace, and/or   entities. Luckily the
    asText() function takes care of all this for me in almost all
    cases. However, it does not handle HtmlCheckBox and
    HtmlRadioButton is a useful way. By default
    HtmlCheckBox.asText() simply returns "on" regardless of
    whether the checkbox is checked or not. HtmlRadioButton
    also returns the same thing regardless of whether the radio
    button is checked or not. Ideally I want asText() to return
    something that indicates whether the check box or radio
    button is checked or not and that is what my patch does.

    Since

    a) its hard to conceive that anyone is depending on the
    current, not-so-useful, implementation of asText()
    b) asText() is already behaving differently than what its
    documentation says ("Return a text representation of this
    element that represents what would be visible to the user if
    this page was shown in a web browser.")

    I thought it would be okay to suggest a change in its
    behavior.

     
  • Marc Guillemot

    Marc Guillemot - 2004-12-16

    Logged In: YES
    user_id=402164

    I can't apply the patches: the format seems to be wrong.
    Make sure to generate them in unified format and not to
    include extra parent folders like "htmlunit.mjb/".

     
  • Mike Bresnahan

    Mike Bresnahan - 2004-12-16

    Logged In: YES
    user_id=263077

    Hmm, sorry. I couldn't figure out how to make 'cvs diff'
    include the file I added since I cannot do 'cvs add'. So I
    created two directories, one with HEAD in it and one with
    HEAD plus my changes, and then used diff(1). I've done this
    before and it didn't cause any problems. Do you know of a
    better way?

    BTW, the diffs are in unified format.

     
  • David D. Kilzer

    David D. Kilzer - 2004-12-29

    Logged In: YES
    user_id=84089

    Mike,

    You can "fake" the "cvs add" function by editing the
    CVS/Entries file manually. Then running "cvs diff -uN" will
    include the new file for you. The format looks like this
    (replace "file.name" with your new file's name):

    /file.name/0/dummy timestamp//

    Yeah, I know, it's a sick hack, but it works. :)

     
  • Mike Bresnahan

    Mike Bresnahan - 2005-01-04

    Logged In: YES
    user_id=263077

    Ah, very clever. I am uploading new diffs.

     
  • Mike Bresnahan

    Mike Bresnahan - 2005-01-04

    Test Case in 'cvs diff' format

     
  • Mike Bresnahan

    Mike Bresnahan - 2005-01-04

    Fix in 'cvs diff' format

     
  • Marc Guillemot

    Marc Guillemot - 2005-01-04

    Logged In: YES
    user_id=402164

    Wouldn't it be more logic to have "checked" and "unchecked"?
    I think that it would better match the description of the
    javadoc:

    "Return a text representation of this element that
    represents what would be visible to the user if this page
    was shown in a web browser. For example, a select element
    would return the currently selected value as text"

     
  • Mike Bresnahan

    Mike Bresnahan - 2005-01-04

    Logged In: YES
    user_id=263077

    I don't know that I agree that checked/unchecked is more
    logical than true/false. They are basically synonyms in this
    context, no? I choose true/false because check boxes and
    radio buttons are generally used to graphically represent
    boolean values and true/false is the conventional string
    representation of the boolean. But I'm not passionate about
    either choice. However it would be nice if check boxes and
    radio buttons used the same words. Is checked/unchecked
    applicable to radio buttons?

     
  • Marc Guillemot

    Marc Guillemot - 2005-01-05

    Logged In: YES
    user_id=402164

    Fixed with "checked" and "unchecked". Thanks for the patches.

     

Log in to post a comment.