Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Possible to Trigger js function with Mojo::UserAgent?

by hesco (Deacon)
on Mar 13, 2016 at 00:49 UTC ( [id://1157568]=perlquestion: print w/replies, xml ) Need Help??

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

I'm using Mojo::UserAgent to access the form here. But rather than an html button, the form submission widget is wired to some javascript like so:

<div class="btn1" id="VALIDBTN" onclick="validate()">Submit</div>

intending to trigger this code:

function validate(){
	submitFlag = true;
	validateFirstName();
	validateLastName();
	validateTown();
	validateDOB();
	if(submitFlag){
		$('#form1').attr('method', 'POST');
		$('#form1').attr('action', '/MVP/voterDetails.do');
		$('#currentSearch').val("1");
		$('#countyName').val($("#county").find("option:selected").text());
		submitForm();		
	}else{
		return false;
	}
}

So far, what I have looks like this:

sub validate_signature {
  my $signature = shift;
  my $base_url = 'https://www.mvp.sos.ga.gov/MVP/mvp.do';
  my %data = (
        firstName => $signature->{'sig_fname'},
         lastName => $signature->{'sig_lname'},
           county => $signature->{'sig_county'},
              dob => $signature->{'sig_dob'},
    currentSearch => 1,
  );
  my $tx = $ua->get( $base_url => \%data );
  print Dumper $tx;
}

Attempts to POST this data yield: "405 - HTTP verb used to access this page is not allowed." and my GET requests get the html of the form, not the results of the javascript function and its POST back to its source.

Curious to know if there is a way to trigger this onclick somehow. Joel Berger's Mojo::Phantom looks interesting and useful but does not seem to do quite what I'm looking for. Any ideas would be welcome.

-- Hugh

if( $lal && $lol ) { $life++; }
if( $insurance->rationing() ) { $people->die(); }

Replies are listed 'Best First'.
Re: Possible to Trigger js function with Mojo::UserAgent?
by thomas895 (Deacon) on Mar 13, 2016 at 02:07 UTC

    In your browser, inspect the network request made using devtools when you submit the form. See if you can replicate the functionality of that JavaScript, and then set/change the relevant fields accordingly.

    -Thomas
    "Excuse me for butting in, but I'm interrupt-driven..."
Re: Possible to Trigger js function with Mojo::UserAgent?
by Anonymous Monk on Mar 13, 2016 at 02:24 UTC

    Curious to know if there is a way to trigger this onclick somehow. Joel Berger's Mojo::Phantom looks interesting and useful but does not seem to do quite what I'm looking for. Any ideas would be welcome.

    Like WWW::Mechanize/LWP, javascript isn't supported, if you want javascript you need something else (phantom)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1157568]
Approved by stevieb
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (5)
As of 2024-03-28 23:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found