> -----Original Message----- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On > Behalf Of Suresh Govindachar > Sent: Thursday, December 14, 2006 9:57 PM > To: perl-win32-users@listserv.ActiveState.com > Subject: Replacing WWW::Mechanize with Win32::OLE via IE > > > Hello, > > I found two good references for using Win32::OLE as a replacement > for WWW::Mechanize on Windows (the first is by Jan Dubois): > > > http://library.n0i.net/programming/perl/pe-rlmonth/issue3/ole_ controls.html > http://www.perl.com/lpt/a/916 > > In my application, the current page being processed has > the javascript lines: > > <img src="/foobar/imgs/image.gif" width="10" height="10"> > <input name="ButtonFoo" type="button" value="Start" > onclick="self.location='/foo/bar/foobar.cgi?do_it=1'; > return false;"> > > My present work-around for clicking the above button are the lines: > > $file = 'https://secure.foo.com/foo/bar/foobar.cgi?do_it=1'; > $ie_object->Navigate($file); > > Question: Is there a better way to click the javascript button > and if so, what? > You should change your use line to be this (so it includes the event model:
use Win32::OLE qw (EVENTS); And add this line just prior to the Click. $object_that_uses_onclick_event->FireEvent("onclick"); As well, I've found the following code helpful in finding certain places in the HTML as well instead of writing foreaches everywhere--I USE THIS sub A LOT. :) if (find_tag($ie_object->{Document}->{Body}->{All},"IMG","alt","alt value",$new_obj)) { $new_obj->Click(); } sub find_tag { my $obj = $_[0]; my $tag = $_[1]; my $type = $_[2]; my $value = $_[3]; my $x = 0; while ($x < $obj->tags($tag)->{length}) { if ($obj->tags($tag)->item($x)->{$type} eq $value) { $_[4] = $obj->tags($tag)->item($x); return 1; } $x++; } return 0; } > Thanks, > > --Suresh > > PS: Here's code fragment I am currently using to fill-out > fields in a form and to click buttons in a form: > > sub fill_form_field > { > my ($ie_object, $name, $value) = @_; > my $ie_document = $ie_object->{Document}; > my $forms = $ie_document->forms; > > foreach my $form (in $forms) > { > print "\tLooking at form: ", $form->name(), " > for fill-in field $name\n"; > if(defined $form->elements($name)) > { > $form->elements($name)->{value} = $value; > last; > } > print "\t\tbut did not find it\n"; > } > } > > sub click_form_button > { > my ($ie_object, $name) = @_; > my $ie_document = $ie_object->Document; > my $forms = $ie_document->forms; > > foreach my $form (in $forms) > { > print "\tLooking at form: ", $form->name(), " > for clickable element $name\n"; > if(defined $form->elements($name)) > { > $form->elements($name)->click; > last; > } > print "\t\tbut did not find it\n"; > } > } > > > _______________________________________________ > Perl-Win32-Users mailing list > Perl-Win32-Users@listserv.ActiveState.com > To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs > > _______________________________________________ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs