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

Monastery, I need help with Mechanize firefox module.I am trying to download a usage file and I have automated to the point where I get a prompt for Opening "file" dialog with two radio buttons open (selected) and save file. I am trying to execute a java-script that will select the save file radio button and then the ok button, but I don't seem to find out how to do that. Any ideas on how to execute the javascript from within my code? Currently my code looks like this:

my $agent = WWW::Mechanize::Firefox->new(autoclose => 0); $agent->get($url); # check if page has a login cached page if ($cached) { $agent->form_number('1'); $agent->field(j_username=>$username); $agent->field(j_password=>$password); $agent->submit(); die unless ($agent->success); } else { #Now we retrieve the download page for downloading usage records. my $usagepage="$url$usagelink"; $agent->get($usagepage); $agent->form_name($usageform); $agent->field("#dateFrom",$datefrom); $agent->field("#dateTo",$dateto); #this now brings out the download prompt dialog box # and requires action $agent->eval_in_page('doExport();); # Need to now obtain file somehow... die unless ($agent->success);

Any help or direction is greatly appreciated.

Replies are listed 'Best First'.
Re: JavaScript POP up in Firefox for open with and save file dialog
by Corion (Patriarch) on Sep 14, 2013 at 07:46 UTC

    So far, the easiest way I found to avoid this "Save As" dialog popping up is to set up Firefox to always save files in Downloads.

    I haven't found a good way to prevent the "Save As" dialog from popping up, or automating it from the outside. The alternative is to find what URL the doExport() function actually accesses, and to ->get() that URL directly instead.