Re: Dynamic Forms, Javascript (what else!) and WWW::Mechanize
Gisle Aas <[email protected]>
| Newsgroups | gmane.comp.lang.perl.modules.lwp |
|---|---|
| Message-ID | <[email protected]> |
Peter Stevens <[email protected]> writes: > The problem is that when the page is first displayed > (i.e. before the javascript [doesn't] execute, these form variables > don't exist. They are apparently created by the javascript. So when I > try > > $mech->field('min', $telno ) ; > > I get an error from HTML::Form: > > No such field 'min' at > /home/mmtest/local/lib/perl5/site_perl/5.8.5/WWW/Mechanize.pm line 1030 > at /home/mmtest/local/lib/perl5/site_perl/5.8.5/HTML/Form.pm line 402 > > So it looks like I just need to convince HTML::Form to create some new > fields, but I couldn't find how to do this. Can anybody explain? You could try to use the undocumented 'push_input' method. It's not doucmented because I did not think anybody would have a reason to modify the form, but as this problem demonstrates there is certainly use cases. HTML::Form should grow an official API to modify the form structure. This is a short demo of how you can add fields with the current version: #/usr/bin/perl -w use strict; use HTML::Form; my $f = HTML::Form->parse(<<EOT, "http://www.example.com"); <form> <input name="foo" value=1> </form> EOT $f->push_input("text", { name => "bar" }); $f->value(bar => 2); print $f->click->as_string; Regards, Gisle