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

Hi All,

I'am use WWW::Mechanize::Firefox to access a java website to generate reports for download. After I choose the report I want I have to enter date parameters for which I want the data for. To do this I click on a link that opens a popup window where you select and fill in values. When the popup opens I do not know how to access it and it times out on me with the following error: "command timed-out at C:/Perl/site/lib/MozRepl/Client.pm line 186" Using applescript I am able to via safari on mac.

do JavaScript "document.aspnetForm.ctl00$ContentPlaceHolder2$selectDay +.value = \"" & pday & "\";" in document 1 of window id win2 do JavaScript "document.aspnetForm.ctl00$ContentPlaceHolder2$selectMon +th.value = \"" & mnth & "\";" in document 1 of window id win2 #delay 5 do JavaScript "document.getElementById('ctl00_ContentPlaceHolder2_btnS +ubmit2').click()" in document 1 of window id win2

Is there a way to do same thing with perl and firefox? What would cause the timeout issue?

Here is my code so far:
use WWW::Mechanize::Firefox; my $mech = WWW::Mechanize::Firefox->new( visible => 1, autoclose => 0, +); $mech->get('https://www.XXX.com/XXX/aspx/XXXLogin.aspx'); sleep(2); $mech->field(username => 'XXX'); sleep 1; # give the page more time $mech->click_button( name => 'btn_LoginSubmit' ); $mech->field(answer1 => 'XXX'); $mech->field(answer2 => 'XXX'); $mech->click_button( name => 'btnKBA_Submit' ); sleep(1); $mech->field(password => 'XXX'); $mech->click_button( name => 'btnPwd_Submit' ); sleep(1); $mech->follow_link( text_regex => qr/Investment Detail/i ); sleep(1); #---Launch Popup windo---# $mech->follow_link( text_regex => qr/Filter/i );

If I can not access the popup then this is not going to work and I am not going to waste any more time with this. so any suggestions and ideas are welcomed. Thank you all in advance.

Replies are listed 'Best First'.
Re: WWW::Mechanize::Firefox popup window help
by Corion (Patriarch) on May 13, 2012 at 17:45 UTC

      Thank you for your time and information. Working on this now.

        I'm having a similar problem that synchronize doesn't seem to solve. I'm trying to automate filling out some forms that get auto-populated by a popup. The popup fires off a js to autofill the previous form. If I use the popup as it's own URL i can access the "form1" just fine (but then it won't autofill the previous page with the js), but when I actually try to navigate using the below code, it can't find "form1".

        Any ideas?

        if($visitFound eq 0){ $oa_mech->get($addv_url); die unless ($oa_mech->success); sleep(2); #get patient ID $oa_mech->click({id => 'ctl00_phFolderContent_Button1', synchr +onize => 0}); for (1..10){ last if $oa_mech->is_visible( xpath => '//*[@id="ctl04_pop +upBase_btnSearch"]'); sleep(1); } $oa_form_name = "form1"; $oa_mech->form_name($oa_form_name); $oa_mech->set_fields( '#ctl04_popupBase_txtSearch' => 'Hester', '#ctl04_popupBase_DOB_Month' => $birthMonth, '#ctl04_popupBase_DOB_Day' => $birthDay, '#ctl04_popupBase_DOB_Year' => $birthYear, ); $oa_mech->click({id => 'ctl04_popupBase_btnSearch', synchroniz +e => 0}); for (1..10){ #wait for visit page to reload last if $oa_mech->is_visible( xpath => '//*[@id="ctl00_phF +olderContent_DateVisited_Year"]'); sleep(1); } }