... I'm trying to use the Scripter class eval method to actually run the code....
You shouldn't have to do that :) any onsubmit or onclick functions should be called by virtue of using a javascript plugin, when you use the submit method
Like the docs say, WWW::Scripter is a subclass of WWW::Mechanize
#!/usr/bin/perl -- use strict; use warnings; use URI; use WWW::Scripter; Main( @ARGV ); exit( 0 ); sub Main { my $w = WWW::Scripter->new( autocheck => 1, show_progress => 1, # prints to stderr ); $w->use_plugin('JavaScript'); #~ $w->add_handler("request_send", sub { shift->dump; return }); #~ $w->add_handler("response_done", sub { shift->dump; return }); $w->timeout(0.00000000001); for my $return ( qw/ false true / ) { warn "BowlingRETURNVALUE => $return \n"; $w->get( data_url($return) ); $w->submit; #~ $w->submit_form( #~ form_number => 0, #~ fields => { qw' user_choice Enter ' }, #~ ); } } BEGIN { my $html = <<'HTML'; <html> <head> <title> localhost form </title> <html> <script type="text/javascript"> function Bowling(){ alert("\nStrike\n"); /* prints to stdout */ return BowlingRETURNVALUE; } </script> </head> <body> <base href="http://localhost/"> <form method="POST" action="http://localhost/" onsubmit="return Bowli +ng();">> <input id="enterbutton" type="submit" name="user_choice" value="Enter" + /> <input type="submit" name="user_choice" value="Leave" /> </form> </body> </html> HTML sub data_url { my $return = shift; my $h = $html; $h =~ s/BowlingRETURNVALUE/$return/; my $u = new URI 'data:'; $u->media_type('text/html'); $u->data( $h ); return $u; } } __END__
As you can see from the log below, first submit doesn't trigger http activity because the onsubmit javascript returns false, but the next one does , because onsubmit callback returns true
Since I don't have a server on localhost, the timeout causes an almost instant internal 500 error -- everything is working as expected
BowlingRETURNVALUE => false ** GET data:text/html;base64,PGh0bWw+ID...Pgo= ==> 200 Document follow +s Strike BowlingRETURNVALUE => true ** GET data:text/html;base64,PGh0bWw+ID...+Cg== ==> 200 Document follo +ws Strike ** POST http://localhost/ ==> 500 Can't connect to localhost:80 (timeo +ut) Error POSTing http://localhost/: Can't connect to localhost:80 (timeou +t) at C:/perl/site/5.14.1/lib/WWW/Scripter.pm line 598
In reply to Re: How do I call a JavaScript function from WWW::Scripter?
by Anonymous Monk
in thread How do I call a JavaScript function from WWW::Scripter?
by bbrelin
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |