Hi,

I am trying to automate a form submission using WWW::Mechanize::Firefox. Populating the form works just fine as expected. But on submitting the form with the function $mech->click_button(), a javascript alert box gets opened. Without preventing the alert box opening, form submission does not happen.

Please find the HTML which opens the confirm dialog box.

<form onsubmit="return onSubmitProfile(this,'Please complete the red e +ntry.','Warning: Incorrect parameters may cause undesired behavior.') +" method="post" action="/goform/formHandlerConfigureProfileSettings"> <table width="100%" bgcolor="#ffffff" align="middle" valign="top"> </table> <fieldset> </fieldset> <fieldset id="content" style="display: none;"> </fieldset> <table > <tbody> <tr cellpadding="6" cellspacing="6" width="100%"> <td width="5%"> </td> <td width="45%"> </td> <td width="50%"> <input type="submit" value="Apply" name="button"> </td> </tr> </tbody> </table> </form>

The javascript function for the same is

function onSubmitProfile(theform,errorMessage,confirmMessage) { if(validateIpSettings() != 0) {alert(errorMessage); return false} var submitConfirm=confirm(confirmMessage) if(submitConfirm==true) { return true } return false }

As a work around for this issue, I used $mech->submit to submit the form by avoiding javascript. But this also avoid the error checking withing the web page. So can anyone help me here to trap the alert message which is displayed during the form submission. Also I tried to trap the alert with the function $mech->eval_in_page. But I could not find any detailed examples to use this function for the same purpose.

Any suggestions in this issue is appreciated.


In reply to (OT) How to override the javascript alert when submitting a form using WWW::Mechanize::Firefox by ajose

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.