Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Dear all,
I uploaded a file in a website using WWW::Mechanize ,
but the thing is that I did not know how to control the "confirm box" generated by the Java script.

Replies are listed 'Best First'.
Re: Access Java script using perl
by marto (Cardinal) on Oct 19, 2009 at 11:17 UTC
Re: Access Java script using perl
by Corion (Patriarch) on Oct 19, 2009 at 11:17 UTC

    WWW::Mechanize does not know Javascript, and it tells you so in its documentation.

    I'm working on an interface to FireFox using MozRepl, which allows you to inspect and react to things that Javascript does on a page. This will require a running instance of FireFox, and I haven't released the module yet.

Re: Access Java script using perl
by moritz (Cardinal) on Oct 19, 2009 at 11:14 UTC
    WWW::Mechanize doesn't understand javascript, so you have to figure out what your browser does when you use the "confirm box", and construct the same request manually.
    Perl 6 - links to (nearly) everything that is Perl 6.

      This is the response I'm getting

      <HTML><TITLE>Expression Of Experience</TITLE> <style type="text/css">textarea.invisible{visibility:hidden}</style><l +ink rel='stylesheet' type='text/css' media='all' href='css/calendar-w +in2k-1.css' title='brown' /> <link rel='stylesheet' type='text/css' media='all' href='css/timesheet +.css' title='timesheet' /> <link rel='stylesheet' type='text/css' href='new_style.css' /> <head><script type='text/javascript' src='./js/timesheet.js' language= +'javascript1.2'></script> <script type='text/javascript' src='./js/downloads/calendar.js' langua +ge='javascript1.2'></script> <script type='text/javascript' src='./js/weekly_report.js' language='j +avascript1.2'></script> <script type='text/javascript' src='./js/downloads/daily_report.js' la +nguage='javascript1.2'></script> <script type='text/javascript' src='./js/add_color.js' language='javas +cript1.2'></script> <script type='text/javascript' src='./js/downloads/calendar.js' langua +ge='javascript1.2'></script> <script type='text/javascript' src='./js/downloads/lang/calendar-en.js +' language='javascript1.2'></script> <script type='text/javascript' src='./js/downloads/calendar-setup.js' +language='javascript1.2'></script> <script type='text/javascript' src='./js/downloads/sorttable.js' langu +age='javascript1.2'></script> <script type='text/javascript' src='./js/revoke_perm.js' language='jav +ascript1.2'></script> <noscript>Sorry! You require a JS enabled web browser.</noscript> </head><BODY BGCOLOR='#ffffff' TEXT='navy' LINK='navy' ALINK='red' VLI +NK='navy' id=background><h4 class=heading_internal> <U>Upload IdeaN +otes File</U></h4> <HR size=1> <BR><FORM NAME=CUR_UPLOAD ENCTYPE='multipart/form-data' ME +THOD=POST ACTION='upload.php' TARGET='xox_frame'><INPUT NAME='LOG_FIL +E' TYPE='HIDDEN' VALUE='/timesheet/logs/UPLOADS/parse_out.abubacker'> +</INPUT><INPUT NAME='XOX_FILE' TYPE='HIDDEN' VALUE='/timesheet/logs/U +PLOADS/abubacker'></INPUT><INPUT NAME='ALREADY_UP' ID='ALREADY_UP' TY +PE='HIDDEN' VALUE='0'></INPUT><INPUT NAME='XOX_DATE' ID='XOX_DATE' TY +PE='HIDDEN' VALUE='0'></INPUT><div id='ERROR_STR'> </div><script> sta=confirm('XOX is already uploaded, +Do you want overwrite the XOX?'); if(sta == true){ // submit the form again document.getElementById('ALREADY_UP'). +value ='1'; document.getElementById('XOX_DATE').va +lue ='13/10/2009'; // alert(document.getElementById( +'ALREADY_UP').value); document.CUR_UPLOAD.submit(); } else { document.getElementById('ERROR_STR').i +nnerHTML= 'The XOX upload cancelled by User'; } </script> </form></body></html>

      I want that true part shuold execute
      please tell me how to figure out this issue

        First you need to understand what the javascript does. Maybe that implies learning javascript and the DOM, if you don't know it already.

        Then you'll find that it just fills out a form with some values, and then submits that. Reading through the WWW::Mechanize documentation and examples you can see that you can emulate the same behavior in perl. That's what you have to do.

        Perl 6 - links to (nearly) everything that is Perl 6.