Sunday, November 13, 2011

Login to Gmail with Win32::IEAutomation


#!/usr/bin/perl

use strict;
use Win32::IEAutomation;
my $VERSION = "1.0";

if($#ARGV != 1)
{
print "\n";
print "************************************************************\n";
print "Usage: Gmail.pl \n";
print "Gmail.pl - Login to gmail account with Internet Explorer.\n";
print "- Chetan Giridhar \n";
print "************************************************************\n";
exit(0);
}
     
# Creating new instance of Internet Explorer.
my $ie = Win32::IEAutomation->new( visible => 1, maximize => 1);
     
# Navigating to www.google.com.
$ie->gotoURL('http://www.google.com');
     
# Finding hyperlinks and clicking them
# Using 'linktext:' option (text of the link shown on web page)
$ie->getLink('linktext:', "Gmail")->Click;

my $user = $ARGV[0];
my $password = $ARGV[1];

# Using 'name:' option
$ie->getTextBox('name:', "Email")->SetValue($user);
$ie->getTextBox('name:', "Passwd")->SetValue($password);


# Finding button and clicking it
# using 'caption:' option
$ie->getButton('caption:', "Sign in")->Click;