Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

Re^10: Not able to select the form with WWW::Mechanize::Firefox using form_with_fields()

by ajose (Acolyte)
on Jun 30, 2011 at 15:26 UTC ( #912203=note: print w/replies, xml ) Need Help??

in reply to Re^9: Not able to select the form with WWW::Mechanize::Firefox using form_with_fields()
in thread Not able to select the form with WWW::Mechanize::Firefox using form_with_fields()

Thanks for the suggestion.

I tried to print the current form after selecting it with the form number. Please see the output for the same.

$current_form = $mech->form_number(10); print "Present value of $input_name: " . $mech->value('DMPName') . "\n +"; print $mech->current_form->{innerHTML}; No elements found for form number 10 at D:\.... Present value of DMPName: Current Name Can't use an undefined value as a HASH reference at D:\...

But by selecting a form other than form number 1 lets me to access elements of every forms in the webpage including the first form.

Please find the stripped down version of the HTML.

<html xmlns=""><head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>DMP configration</title> <meta http-equiv="pragma" content="nocache" /> <link href="../ormats.css" type="text/css" rel="stylesheet"/> <script src="../config.js" type="text/javascript"> </script> <style type="text/css"> .styleColorSpan {color: #CCCCCC} .stylePositionTable {position:relative;top:5px;} </style> </head> <!-- onLoad( ) --> <!-- --> <body class="scrollbar_black" bgColor=#000000 onload="onLoad( )"> <table class="toptable" cellpadding="1" cellspacing="2" height="100%" +width="100%" border="0"> <!-- <table class="toptable" cellpadding="1" width="100%" height=" +100%" border="0"> --> <tr height="100%"> <td valign="top"> <table width="100%" align=top bgColor=#ffffff vAlign=top> <tr width="100%" cellspacing="0" cellpadding="0"> <form action="/goform/formHandlerConfigureDMPName" method="pos +t" onsubmit = "return validateDMPNameOnSubmit(this)"> <td width="5%"><img src="../invis.gif" alt="" width="50" heigh +t="30"/></td> <td width="45%">Digital Media Player Name:</td> <td width="50%"><input type="text" name="DMPName" value="mmmmm +mmm" maxlength="129"/>&nbsp;&nbsp;<input type="submit" value="Apply"/ +></td> </form> </tr> <tr> <form action="/goform/formHandlerConfigureActive" method="get" + onsubmit="return onSubmitActive('Warning: Incorrect parameters may c +ause undesired behavior. To save the new setting, click Ok.')"> <td>&nbsp;</td> <td>Active:</td> <td><select id="oSelectActive" name="active"><option value="0" +>0</option><option value="1">1</option><option value="2">2</option><o +ption value="3">3</option></select>&nbsp;&nbsp;<input type="submit" v +alue="Apply"/></td> </form> </tr> <tr> <form action="/goform/formHandlerConfigure" method="get"> <td>&nbsp;</td> <td>choose Profile to be configured:</td> <td><select id="oSelectChoose" name="Nr"><option value="1">1</ +option><option value="2">2</option><option value="3">3</option></sele +ct>&nbsp;&nbsp;<input type="submit" value="Show"/></td></td> </form> </tr> </table> <fieldset> <legend><span class="styleColorSpan"><b>Profile 1 </b></span>< +/legend> <form action="/goform/formHandlerConfigureSettings" method="post" +onsubmit="return onSubmit(this,'Please complete the red entry.','Warn +ing: Incorrect parameters may cause undesired behavior. To save the n +ew settings, click Ok.','0')"> <table width="100%" align=middle bgColor=#ffffff vAlign=top> <tr width="100%" cellspacing="0" cellpadding="0"> <td width="5%"></td> <td width="45%">Name:</td> <td width="50%"><input type="text" name="Name" /></td> </tr> </table> <fieldset> <legend><span class="styleColorSpan"><b>Settings</b></span></l +egend> <table width="100%" align=middle bgColor=#ffffff vAlign=top> <tr width="100%" cellspacing="0" cellpadding="0"> <td width="5%"><img src="../invis.gif" alt="" width="50" heigh +t="30"/></td> <td width="45%">Service Set:</td> <script type="text/JavaScript"> var myVar_IfWired = "1"; if(myVar_IfWired != 0){ var myCounter = 0; var myCounter1 = "10"; var aspgetstringval = "TEST1zirgtspghwqTEST2zirgtspghwqTES +T3zirgtspghwqTEST4zirgtspghwqTEST5zirgtspghwq"; var mySplitResult = aspgetstringval.split("zirgtspghwq"); document.writeln('<td><select id="oSelectType" nam +e="S" onchange="onSelectType()">'); document.writeln('<option value="NONE">Select Opti +on</option>'); while(myCounter < myCounter1){ var webpagedisplay = mySplitResult[myCounter]; document.writeln('<option value="'+mySplitResult[m +yCounter]+'">'+webpagedisplay+'</option>'); myCounter++; } document.writeln('<option value="MANUAL">CONFIGURE MANUALL +Y</option>'); document.writeln('</select></td>'); } function toggle2(id, link) { var e = document.getElementById(id); if ( == "") { = "none"; link.innerHTML = "<b> [+] ADVANCE SETTING </b>"; } else { = ""; link.innerHTML = "<b> [-] ADVANCE SETTING </b>"; } } </script> </tr> <tr> <!--td>&nbsp;</td> <td> Type:</td> <td><select id="oSelectType" name="Sec" onchange="onSelectType +()"><option value="NONE">No <option value="WEP">WEP<option value="WPA +">WPA</select></td--> </tr> </table> <span id="oSpanManualConfig"> <table width="100%" align=middle bgColor=#ffffff vAlign=top> </table> </span> </fieldset> <a href="#" class="styleColorSpan" onclick="toggle2('content', thi +s)"><b>[+] ADVANCE SETTINGS</b></a> <fieldset id="content" style="display:none" > <legend><span class="styleColorSpan"><b> Advance Setting</b></ +span></legend> <fieldset> <legend><span class="styleColorSpan"><b>Pror</b></span></legen +d> <table width="100%" align=middle bgColor=#ffffff vAlign=top> <tr> <td>&nbsp;</td> <td>ver Port:</td> <td><input id="oTextProxy" type="text" name="Prox" value="" ma +xlength="5" onKeyUp="onKeyUpText()"/></td> </tr> </table> </fieldset> <fieldset> <legend><span class="styleColorSpan"><b>ngs</b></span></legend +> <table width="100%" align=middle bgColor=#ffffff vAlign=top> <tr> <td width="45%">Use DHCP:</td> <td width="50%"><input id="oCheckboxDhcp" type="checkbox" name +="DHCPt" value="" onclick="onClickCheckboxDhcp()"> DHCP</input></td> </tr> </table> </fieldset> </fieldset> <table > <tr width="100%" cellspacing="6" cellpadding="6"> <td width="50%"><input type="submit" name=button value="Apply" +/></td> </tr> </table> </form> </fieldset> </td> </tr> </table> </body> </html>

Hope this gives you much information to work around the problem.

  • Comment on Re^10: Not able to select the form with WWW::Mechanize::Firefox using form_with_fields()
  • Select or Download Code

Replies are listed 'Best First'.
Re^11: Not able to select the form with WWW::Mechanize::Firefox using form_with_fields()
by Corion (Pope) on Jun 30, 2011 at 16:28 UTC


    Looking at the source code as Firefox renders it, the problem becomes apparent immediately:

    <form onsubmit="return validateDMPNameOnSubmit(this)" method="post" ac +tion="/goform/formHandlerConfigureDMPName"></form> <td width="5%"> <td width="45%">Digital Media Player Name:</td> <td width="50%"> <input type="text" maxlength="129" value="mmmmmmmm" name="DMPName"> <input type="submit" value="Apply"> </td>

    Firefox happily (and likely in accordance with some HTML specification) moves all the input elements outside of the form, as the form nastily spans across <td> elemenst without respecting their allowed nesting.

    As WWW::Mechanize::Firefox relies on Firefox doing the heavy lifting, there is nothing I can do. Maybe you can work around things by specifying explicit XPath expressions to get at the respective DOM elements.

    Your post highlighted another error - currently, ->form_with_fields will not respect <select> or <textarea> elements - this will be changed in the next version.

      Thanks for the reply. I might use WWW::Mechanize to fill the problematic form. I can still use W::M::F for filling the form which has javascript.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://912203]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (10)
As of 2018-07-23 15:58 GMT
Find Nodes?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?

    Results (472 votes). Check out past polls.