Thanks Corion!

So here it is:

#!/usr/bin/perl -w use strict; use Data::Dumper; use WWW::Mechanize::Firefox; my $mech = WWW::Mechanize::Firefox->new( launch => '/usr/bin/firefox', tab=>'current', frames => 1, ); $mech->get('http://www.example.com'); # wait for JS to render the login button my $retries = 10; #by xpath while ($retries-- and ! $mech->is_visible( {xpath => '//*[@id="login"] +' } )) { sleep 1; }; die "Timeout while waiting for site to appear" if 0 > $retries; print "waitiing retries = $retries\n"; #type the uid & pw $mech->field( username => 'username'); #by name $mech->field( password => 'password'); #by name #sync cos hangs here otherwise $mech->click( {id=>'login', synchronize => 0}); #by id here my $string; my @elements = $mech->xpath('xpath/selector/to/secret/question'); #by +xpath here for(my $x=0;$x<=$#elements;$x++){ $string = $elements[$x]->{innerHTML}; #get the string print "secret question is elements[$x] = $string\n"; #in case ther +e are multiple matches } #ok you need some regex here to decide which question is being asked a +nd reply with corresponding answer $mech->field( SecQuestion => 'secret answer'); #by name here $mech->click( {id=>"confirm", synchronize => 0});

There seemed to be issues about the match of the secret question array having multiple responses.

You asked for many elements but seem to only want a single item. Did you forget to pass the 'single' option with a true value? Pass 'all => 1' to suppress this message and receive the count of item +s.
I think it was trouble shooting lines of code I had added that put me in the wrong iframe... or something.

Thanks for the hints, they really helped!

z

In reply to Re^2: How to get WWW::Mechaize::Firefox to get text? by zerocred
in thread How to get WWW::Mechaize::Firefox to get text? by zerocred

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.