Hi, This is sort of a bug report, as well as a patch submission.
Today I was writing a test case using Test::WWW::Mechanize,
and accessing an HTML::Form object to do some in-depth testing
of an application. I noticed that HTML::Form only sometimes
filled in the Input object's value_name field, which I
was using in my test cases and getting inconsistent results
with it.
Depending on the location of the name, HTML::Form would
only sometimes catch it and assign it to value_name. For
example, it correctly set value_name when the HTML code
looked like:
<label>
<input type="radio" name="r1" value="1">One
</label>
And it also works when there were no label tags, eg:
<input type="radio" name="r1" value="1">One
But when the following HTML was used it didn't work:
(Note how the word "One" precedes the input tag)
<label>
One
<input type="radio" name="r1" value="1">
</label>
Neither did the following work:
<label for="r1">One</label>
<input type="radio" name="r1" id="r1" value="1">
I patched a local copy of HTML::Form to properly pull
out the text in all three scenarios -- when <label> tags
are used -- and assign it to value_name. I've seen two
benefits from this:
1. When the HTML::Form::dump is called, radio
buttons will have names that line up with the
correct radio button. (sometimes they can be
lined up incorrectly, or be omitted altogether)
2. I can reference radio buttons by their labels
rather than their value attribute. This is
handy if the value is dynamic and not known at
the time the test case is being written, eg:
my $carrier = 'USPS';
my $input = $mech->current_form->find_input('carrier.id');
my %values;
@values{ $input->possible_values } = $input->value_names;
$input->value( $values{$carrier} );
This patch should handle label tags where the input
tag is nested within the label, as well as label tags
that reference another input field by it's id using
the "for" attribute. It will assign the label name
to the input tag so that it can be found in
$input->value_names.
Anyway, the patch is attached. I'd appreciate comments,
and would love to see this included in the standard
distro. Test case patches are also included, and all
test cases pass.
--
Dan
___________________________________________________________
Dan Kubb Email: [EMAIL PROTECTED]
AutoPilot Marketing Phone: +1 (604) 820-0212
33699 Grewall Cres. Cell: +1 (604) 825-9212
Mission, B.C., Canada Web: http://www.onautopilot.com
V2V 7B7
___________________________________________________________
HTML-Form.patch
Description: Binary data
