Corion, my script also gives me a javascript alert.

My larger script uploads many data files. Some data trigger the alert and others don't, but I have no way of predicting which data will trigger the alert. The alert is not a problem, other than the fact that I need to get past it.

When the alert occurs, I can use $mech->back to escape it. However, I don't know of a way to detect when it occurs.

"$mech->is_visible()" in conditional statements don't work, as you can see if you run the script--the alert takes over the whole screen, but "form_with_fields('speciesList')" is returned as visible. Neither "$mech->submit()" nor "$mech->submit_form()" work for me on this webpage--the form just gets cleared and the page reloads without submitting.

Any ideas? I would like to either disable the javascript alert (but not all javascript) at this step, or detect when it is triggered and use "$mech->back" to escape it.

#!/usr/bin/perl use strict; use warnings; use WWW::Mechanize::Firefox; my $mech = WWW::Mechanize::Firefox->new(autoclose => 0); $mech->get('http://david.abcc.ncifcrf.gov/summary.jsp'); $mech->click({ xpath => ('//*[@href="Upload a Gene List or Population" +]', single => 1), synchronize => 0 }); $mech->form_name('frmManager'); $mech->set_fields( 'pasteBox' => "RRI1, YLR149C, FUN19, YBR285W, ALD3, CUE5, +RTC3, AIM3, YDL199C, FMP45, AST2, GIP2, YKL091C, YKL133C, GLG2, SYM1, VHS3, YJR124C, MCH1, MHO +1, IKS1, RKM1, STF2, SAC1, ATG7, YAK1", 'Identifier' => "OFFICIAL_GENE_SYMBOL", ); $mech->click ({ xpath => ('//input[@name="rbUploadType" and @value="li +st"]', single => 1), synchronize => 0 }); $mech->click({xpath => ('//*[@value="Submit List"]', single => 1), syn +chronize => 0}); sleep 2; if ($mech->is_visible($mech->form_with_fields('speciesList'))) { print "It's visible.\n"; }


In reply to Re^4: (OT) How to override the javascript alert when submitting a form using WWW::Mechanize::Firefox by jbernest
in thread (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.