Write a Script in QTP to count the unread emails of a gmail account.

In order to count the unread emails of a gmail account you need to be logged into the Gmail account and then run this script which will count all the unread email and display the no of unread emails. We will use the GetROProperty (Get Run Time Object Property) to get the no of unread emails ex Inbox (25) and then replace Inbox, (, ) with a null and then print only the number.


The reason for us to use the GetROProperty on the Inbox Link is that the count of unread mails is dynamic and so we need to get the innertext and print the unread emails. So no matter you run any number of times you will get the exact number of unread emails in gmail account. If no unread emails are there then it will print a message saying " No Unread Emails" else it will print "You have xxx unread emails in your inbox"

'You need to be logged into the Gmail account
Browser("title:=Gmail.*").Page("title:=Gmail.*").Link("innertext:=Inbox.*").Click
Browser("title:=Gmail.*").Page("title:=Gmail.*").Sync

'To get the innertext of inbox link
inboxcount = Browser("title:=Gmail.*").Page("title:=Gmail.*").Link("innertext:=Inbox.*").getroproperty("innertext")
If inboxcount = "Inbox" Then
Print "No Unread Emails."
ExitAction
Else
emailcount = replace(inboxcount, "Inbox","") 'replaces inbox with space
emailcount = Rtrim(ltrim(emailcount)) 'removes all the spaces
emailcount = replace(emailcount, "(","")
emailcount = replace(emailcount, ")","")
Print "You have "&emailcount& " unread emails in your inbox."
End If

0 comments:

Post a Comment

/* Tynt Insight tracker ----------------------------------------------- */