Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
The following code can be used to script Internet Explorer actions. The exemple chosen is here is to fill in a form and then validate it through a perl script.

For this test script, let's imagine we have a HTML form named 'log_form' (<form ... name='log_form'>), a login input named 'login' ((<input type='text' name='login'>), a password input named 'pass' and a submit button named 'go'.

To find more information about how to drive IE, have a look here : http://msdn.microsoft.com/workshop/browser/webbrowser/reference/objects/internetexplorer.asp
use Win32::OLE qw( EVENTS in with valof ); use Win32::OLE::Variant; Win32::OLE->Option( Warn => 0 ); $HomePage = "http://www.greyhats.org/new/"; $IE = Win32::OLE->GetActiveObject( 'InternetExplorer.Application' ); if( ! defined $IE ) { print "Can not find open object. Creating one...\n"; $IE = Win32::OLE->new( 'InternetExplorer.Application', "Quit" ) or die "Unable to create a IE Object\n"; } Win32::OLE->WithEvents( $IE, \&cleanExit, 'DWebBrowserEvents2' ); $IE->{Visible} = 1; $IE->{RegisterAsDropTarget} = 1; $IE->{RegisterAsBrowser} = 1; $IE->Navigate( $HomePage ); # Let IE load the page while( $IE->{Busy} ) { while ($IE->SpinMessageLoop()) { select undef,undef,undef,0.25; } } $Doc = $IE->{Document}; $forms = $Doc->{forms} or die "Unable to retrieve forms"; $form = $forms->item("log_form") or die "Unable to find my form"; $elements = $form->{elements} or die "Can't get the elements"; $login = $elements->item("login",0) or die "Where is my login !?"; $pass = $elements->item("pass", 0) or die "I wonder why there isn't a +pass"; $go = $elements->item("go", 0) or die "I want my button"; $login->{value} = "zejames"; $pass->{value} = "test"; $go->click; # Do whatever you want. sub cleanExit { my( $obj, $event, @args ) = @_; if ($event eq "OnQuit") { print "Terminating\n"; undef $obj; exit(1); } }

In reply to Driving Internet Explorer with Perl by zejames

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (7)
As of 2024-04-16 11:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found