Hi Monks,
I'm trying to traverse some links and forms which use javascript in the data =( and am using Win32::IE::Mechanize. The issue that I'm having is that I want to add one more value to a form before submitting it and can't seem to work out how???
Everything seems nicely geared towards getting and setting existing values, but I'm now sure on how to create a new one. Win32::IE::Input seems to have a 'new' method, but I'm not sure how to implement it.... Here is what I have....

Take one vanilla form...
<html> <body> <script language="JavaScript"> function fun() { document.form1.submit() } </script> <form name='form1' action="http://www.msn.com"> <input type=hidden name="Fruit" value="apple"> <input type=hidden name="Animal" value="dog"> <input type=hidden name="language" value="perl"> </form> <a href="javascript:fun()">A link</a> </body> </html>

Now to submit the form use something like...
use Win32::IE::Mechanize; use Win32::IE::Input; use warnings; use strict; #location of the html with the form my $url = "http://location.of.test.file/test.html"; my $ie = Win32::IE::Mechanize->new(visible => 1); #get the page $ie->get($url); #select the form my $form = $ie->form_name('form1'); #This is the bit I'm stuck on... #Its going to need a name, type and value my $new1 = Win32::IE::Input->new(); print "NEW : $new1 " . $new1->name . "\n"; #This should print out the existing list of inputs PLUS the one I just + added my @inputs = $form->inputs(); my $c = 1; foreach my $i ( @inputs ) { print "Input$c : " . $i->name . " : " . $i->value . " : " . $i +->type . "\n"; $c++; } #find the link and follow ...this works fine my $link = $ie->find_link( url_regex => qr/fun/i ); my $ll = $link->url; $ie->get($ll);
The output from the script shows the current inputs, but not the new one...half expected because I'm not sure how to put it together. I imagine you'll need to...

1. Create an input instance
2. Populate input with name,value,type
3. Add input to current form

Can someone point me in the right direction as to how this is done.
Regards Paul.

In reply to Win32::IE::Input by thekestrel

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.