Write a Script to delete all the spam mails in Gmail

We will write a script in QTP for deleting all the spam mails in Gmail Account. What we will do is first we will get the innertext of the Spam Link using GetROProperty so that if there are no spam mails then we will exit the test using ExitTest method or can use ExitAction method if we want to only exit that particular action.


If there are spam mails then we will count the unread spam mails and then display it to the user and then delete all the spam mails by checking all the check boxes and clicking the delete forever button. To check all the check boxed we will create a description object and add properties to it WebCheckBox Property. We will use the Childobjects method to get all the checkboxes and using the count method we will get the number of checkboxed. By using a For loop we will set the Checkbox to On so that all will be selected and then click the Delete Forever button to delete the mails.

'Script to Delete spam messages from Gmail
'First get the spam count. if there are no spam mails then exit test
'using GetROProperty to get the innertext of the Spam Link

spamct = browser("title:=Gmail.*").Page("title:=Gmail.*").link("innertext:=Spam.*").GetROProperty("innertext")

'Checking whether spam mails are there or not

If spamct = "Spam" Then
Print "No spam Mails"

'Since there are no spam mail you can exit Test or Exit Action. Based on users decision

ExitTest

'If spam mails are present then we will enter the else part

Else

'we will take the innertext of Spam link and remove all the unnecessary characters and print only the spam count.

spamcount = Replace(spamct, "spam", "") 'replacing the spam word with space
spamcount = Trim(spamcount)
spamcount = Replace(spamcount, "(","")
spamcount = Replace(spamcount, ")","")

'Printing the number of spam mails to the user

print "You have "&spamcount& " unread spam mails and all the available spam mails will be deleted forever"


'clicking on the spam link

Browser("title:=Gmail.*").Page("title:=Gmail.*").sync
Browser("title:=Gmail.*").Page("title:=Gmail.*").link("innertext:=Spam.*").Click

'Creating a description object for check boxes

Set abc_obj = Description.Create
abc_obj("micclass").Value = "WebCheckBox"

'Getting the childobjects i.e Checkboxes

Set browser_checkbox = Browser("title:=Gmail.*").Page("title:=Gmail.*").childobjects(abc_obj)

'using a for loop to set the check boxes to on position i.e selecting them

For i = 0 to browser_checkbox.Count - 1
browser_checkbox(i).Set "ON"
Next

'Clicking on the delete forever button to delete the spam mails

Browser("title:=Gmail.*").Page("title:=Gmail.*").webElement("innertext:=Delete forever","index:=*.*").Click

'using windows script host environment to make sure that the delete forever button is clicked

Set wsh = CreateObject("wscript.Shell")
wsh.sendkeys ("{Enter}")

End If

1 comments:

Annie Monie said...

It helps to generate speedy responses and it does leave a digital mark which can be calculated instantly. Along with general offerings like open, delivery rates and click through, the popular providers of Email Services offer tools that calculates sale, file downloads conversions, newsletter subscriptions, event registrations, social bookmarking and et al.

email delivery

Post a Comment

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