GMail Logo
There are many tutorials that can be found on the Internet that show how QTP methods can be used in everyday test development. However, there are very few lessons available for developers starting in QTP that teach how to automate entire applications, or parts of them. This is such a tutorial and will show how parts of GMail can be automated through QuickTest Professional. GMail is an extremely dynamic UI and always quite challenging to automate successfully. Its dynamic behavior also makes it an excellent candidate to practice QTP with and sharpen your skills. I will try to show a few techniques that can be helpful in automating GMail, and through it, automating any dynamic application that you encounter.
GMail Login
I’m sure everyone who has worked with GMail would have already created this part of the script and chances are that it would have been created as a function. The same has been done here with the help of conditional statements:
Function GMailLogin(sUserName, sPassword) GMailLogin = False With Browser("title:=Gmail.*").Page("micclass:=Page") 'Check if the UserName field exists If .WebEdit("html id:=Email").Exist(0) Then .WebEdit("html id:=Email").Set sUserName 'Set UserName .WebEdit("html id:=Passwd").SetSecure sPassword 'Set Password .WebButton("name:=Sign in").Click 'Click Submit .Sync End If 'Check for Link Inbox(xyz) If .Link("innertext:=Inbox.*").Exist(15) Then GMailLogin = True End With End Function 'Usage 1: MsgBox GMailLogin("yourUserName", "yourPassword") 'Usage 2: If GMailLogin("yourUserName", "yourPassword") = True Then 'Continue with test Else 'Stop End If
Sign Out of GMail
No tricks here. A simple inline DP or OR statement would accomplish Signing out of GMail:
Browser("title:=Gmail.*").Page("micclass:=Page").Link("innertext:=Sign Out").Click 'Update March 15, 2011: The GMail interface has changed slightly. 'If the above does not work, please try this: Browser("title:=Gmail.*").Page("micclass:=Page").Link("innertext:=Sign Out", "class:=gbml1").Click
Get New Email Count
Each automation developer prefers a different approach of retrieving desired values from blocks or text. For each task which requires a value to be retrieved, 3 techniques are demonstrated for the retrieval of expected values: Split, RegExp and Left/Right. But first, we must retrieve the entire string containing the number of Unread emails:
Unread Emails
Retrieve ‘Inbox (3)’
sLink = Browser("title:=Gmail.*").Page("title:=Gmail.*").Link("innertext:=Inbox.*")_ .GetROProperty("innertext")
Once the string containing the number of unread e-mails is retrieved, one of the following approaches can be used to produce the same result:
Split
iEmails = Split(sLink, " ")(1) '(3) iEmails = Replace(iEmails, "(", "") '3) iEmails = Replace(iEmails, ")", "") '3 Print iEmails
RegExp
Set oRegExp = New RegExp oRegExp.Pattern = "\d+" Set oMatches = oRegExp.Execute(sLink) 'oMatches(0) = 3 iEmails = oMatches(0) Print iEmails
Left, Right
iPosition = InStr(1, sLink, "(") iEmails = Right(sLink, Len(sLink) - iPosition) '3 iEmails = Left(iEmails, Len(iEmails) - 1) Print iEmails
Get Total Emails Count
Unlike the scenario above, which retrieved the number of unread e-mails in the AUT, this section shows how the total number of e-mails can be retrieved. Just like the previous scenario, a simple inline DP statement can be used to retrieve the number string that contains the value we are looking for:
Total Emails
Retrieve ’1 – 4 of 4′
sText = Browser("title:=Gmail.*").Page("title:=Gmail.*")_ .WebElement("innertext:=\d+ - \d+ of \d+", "index:=0").GetROProperty("innertext")
After retrieving the entire string, one of the following approaches can be used to produce the result:
Split
iEmails = Split(sText, "of")(1) ' 4 iEmails = Split(iEmails, " ")(1) '4 Print iEmails
RegExp
Set oRegExp = New RegExp oRegExp.Global = True oRegExp.Pattern = "\d+" Set oMatches = oRegExp.Execute(sText) 'oMatches(oMatches.Count - 1) = 4 iEmails = oMatches(oMatches.Count - 1) Print iEmails
Left, Right
iLoc_Of = InStr(1, sText, "of") iTotals = Right(sText, Len(sText) - iLoc_Of - 1) iTotals = Trim(iTotals) Print iTotals
Space Used by Emails
One important, and a little complex (in comparison to the above scenarios) one: retrieving the space used by Emails. The process will remain the same, but notice the usage of the wild card character for the WebElement:
Space Used
Retrieve ‘You are currently using 0 MB (0%) of your 7430 MB.’
sText = Browser("title:=Gmail.*").Page("title:=Gmail.*")_ .WebElement("innertext:=You are currently using.*of your.*", "index:=0")_ .GetROProperty("innertext")
The above inline DP statement will retrieve and store the entire string with sText. Once executed, one of the following methods can be used to retrieve the result:
Split
iSpace = Trim(Split(sText, "You are currently using")(1)) '0 MB (0%) of your 7430 MB. iSpace = Split(iSpace, " ")(0) '0 Print iSpace
RegExp
Set oRegExp = New RegExp oRegExp.Pattern = "\d+" Set oMatches = oRegExp.Execute(sText) iSpace = oMatches(0) Print iSpace
Left, Right
iLoc_MB = InStr(1, sText, "MB") sText = Trim(Left(sText, iLoc_MB - 1)) 'You are currently using xx iSpace = Right(sText, Len(sText) - InStrRev(sText, " ")) '0 Print iSpace
GMail Auto-Generated Response Message
If you would like to check the existence of any of the messages as shown below, accessing the class of the Element will suffice to retrieve the entire text and verify it against our expected result.
Out of the numerous ways these messages could be checked, I am going to show 2 possible uses with a description object and an inline DP statement.
Inline DP
Browser("title:=Gmail.*").Page("micclass:=Page")_ .WebElement("class:=vh", "html tag:=TD", "index:=0").GetROProperty("innertext")
Description Object + ChildObjects
Dim oDesc, colObject Set oDesc = Description.Create oDesc("micclass").Value = "WebElement" oDesc("class").Value = "vh" Set colObject = Browser("title:=Gmail.*").Page("micclass:=Page").ChildObjects(oDesc) MsgBox colObject(0).GetROProperty("innertext")
Finding Row with Containing Text
To find an e-mail row using text, we can either create a custom function or use the GetRowWithCellText method of the WebTable. However, chances are that the custom function will not prove to be quite as fast. A custom function has been created to find the row containing the specified text:
Custom Function
Function FindMailRow(sText) Dim oTable, iRows, ix FindMailRow = -1 With Browser("title:=Gmail.*").Page("micclass:=Page").WebTable("class:=F cf zt") iRows = .GetROProperty("rows") For ix = 1 to iRows sMailText = .GetCellData(ix, 3) & .GetCellData(ix, 5) & .GetCellData(ix, 7) If InStr(1, LCase(Replace(sMailText, vbLf, " ")), LCase(sText)) Then FindMailRow = ix Exit Function End If Next End With End Function 'Usage: MsgBox FindMailRow("Text")
The outcome will be the same when using the GetRowWithCellText method, but with a smaller performance footprint.
GetRowWithCellText
MsgBox Browser("title:=Gmail.*").Page("micclass:=Page").WebTable("class:=F cf zt")_ .GetRowWithCellText("Redefining")
The custom function took 2.45 seconds to find the row whereas GetRowWithCellText took only 1.22 seconds.
Reading Emails
The above method can be coupled with a click event to find and open the e-mail that is to be read. A simple inline DP statement can be used to click the target row and open the e-mail. In this example, we’re going to click on the 2nd Email:

'I have used 'Access Gmail' but you can use any (unique) text on that row iRow = Browser("title:=Gmail.*").Page("micclass:=Page").WebTable("class:=F cf zt")_ .GetRowWithCellText("Access Gmail") With Browser("title:=Gmail.*").Page("micclass:=Page").WebTable("class:=F cf zt") .ChildItem(iRow, 3, "WebElement", 0).Click End With
When the row is clicked, the Email is opened for reading:
Row 2: Access Gmail
I hope this article provides more in-depth knowledge of testing complex Web applications. I hope to find more such applications in the future to share with everyone. If you feel there is a scenario that this article lacks, or will become more useful with the addition of one, please do let me know.
If you have any questions, please ask them in the comments section. If your query is confidential, please use the Contact Form to send me an e-mail instead.
{ 91 comments… read them below or add one }
how to handle dynamic object like deleting last email in the page every time?
Sunitha,
The following code can be used to delete the last received e-mail each time:
With Browser("title:=Gmail.*").Page("micclass:=Page") .WebTable("class:=F cf zt").ChildItem(1, 1, "WebCheckBox", 0).Set "ON" Setting.WebPackage("ReplayType") = 2 .WebElement("innertext:=Delete", "index:=0").Click Setting.WebPackage("ReplayType") = 1 End WithHI, the above script is running correctly for the first time.
when i run the sams script for next time it is displaying msg as “webtable objects description matches more than one of the objects in your application.”
once i close gmail and open again the script is running fine for the first time.
what may be the reason.can anybody suggest
Hi Anshoo
When I am opening mercury tours application it is showing
FATAL ERROR: register_globals is disabled in php.ini, please enable it!
What shall i do ??
how can i enable in php.ini ?
Hi Manas,
I also see the same error.
Please see San’s (below) note on the issue. Thank you, San.
Hi Manas,
It is not a problem of QTP, even this is a problem of PHP.INI configuration file setting. There is a PHP.INI file on the server, where you have to set this variable enable.
Thanks
Hello,
What is the code if you want to read all unread emails in the gmail account one by one.
Thanks,
Hannah
The following code will highlight all the unread conversations:
Set oDesc = Description.Create oDesc("micclass").Value = "WebElement" oDesc("class").Value = "zF" Set colChild = Page("title:=.*mail.*").ChildObjects(oDesc) If colChild.Count > 0 Then For ix = 0 to colChild.Count - 1 colChild(ix).Highlight Next End If Set colChild = Nothing Set oDesc = NothingThe following code will click all unread e-mails:
Set oDesc = Description.Create oDesc("micclass").Value = "WebElement" oDesc("class").Value = "zF" With Page("title:=.*mail.*") Set colChild = .ChildObjects(oDesc) For ix = 0 to colChild.Count - 1 colChild(ix).Click iy = 0 Do iy = iy + 1 Set oDesc = Description.Create oDesc("micclass").Value = "WebElement" oDesc("class").Value = "iw" Set colChild = Page("title:=.*mail.*").ChildObjects(oDesc) Loop Until (colChild.Count > 0) OR (iy = 15) If Not colChild.Count > 0 Then Exit For .Link("innertext:=Inbox.*", "index:=0").Click If Not .WebElement("class:=yX xY", "index:=0").Exist(10) Then Exit For Set oDesc = Description.Create oDesc("micclass").Value = "WebElement" oDesc("class").Value = "zF" Set colChild = .ChildObjects(oDesc) If colChild.Count = 0 Then Exit For End If ix = -1 Next End With Set colChild = Nothing Set oDesc = NothingHello,
I have a question. Why do I get an error in the clicking of Sign Out. The frame’s value changes:
Frame(“c1nzi95jbotg2z”).Link(“Sign out”).Click
Please advise.
Hannah
Hannah,
In a Web application, you can completely skip the
Frameobject and refer directly to the child object. In your case then, you can write an inline statement like this:Browser("").Page("").Link("").ClickHowever, to answer your question: your observation is absolutely correct. I did notice that Google has dynamic frames that change frequently. I think the best way to handle this would be through a Regular Expression or ChildObjects. However, I would still recommend to avoid the Frame completely and use Browser/Page as the parent in the hierarchy.
Hi Hannah,
Did u find the solution? I am facing the same problem. I tried avoiding the frame part, but it didn’t work.
I tried with the following but not succeded.
1. ‘The frame name starts with c always
Browser(“browserName”).Page(“Pagename”).Frame(“c.*”).Link(“Sign out).click -9999, -9999
2. Browser(“browserName”).Page(“Pagename”).Link(“Sign out).click -9999, -9999
Let me know how to handle this.
Thanks
kishore
Hi Anshoo,
I have web page consist of Data table & many links.
My query is that i want to automate my links.
Anu,
Not sure I understand the question? How do you want to automate these links??
Helllo
I am triyng to send a mail throuhg QTP from Gmail.
How do I can write in the field of the body mail, if QTP recognize that object as a WebElement and it doestn allow to set any value?
Thnks
Sorry by my english. I hope you understand to me.
In the inline hierarchy, after the WebElement, insert the following code and see if it works:
this is the best code & coverage ever I got online….
Thanks a Ton…wonderfull…….
:)
I am glad some to know some one who really meant to help others!!
God Bless you with more knowlege.
hello all!!!
Do u know how to write a script sending test mail ?
Michelo, please see this post: http://relevantcodes.com/cdo-send-email-from-yahoo-hotmail-live-aol-or-gmail/
Hi,
I am unable to click on singout button in gmail using qtp. When i record it, it shows as
Browser(“browserName”).Page(“Pagename”).Frame(“c34fas4afa54″).Link(“Sign out”).click
The frame name is dynamic . So while recording it shows one frame name and while executing it shows diffrent framename and it fails. I tried the following but not able to succeed.
1. ”The frame name starts with c always
Browser(“browserName”).Page(“Pagename”).Frame(“c.*”).Link(“Sign out”).click -9999, -9999
2. ”I ignored the frame as some says it is not neccessary
Browser(“browserName”).Page(“Pagename”).Link(“Sign out).click -9999, -9999
In bot the cases, the test is failing as it not able to find the object.
Let me know how to handle this.
Kishore,
If you want to apply a RegEx to the Frame object, you can do it like this: Click here. You may have to use an Index value as well.
use this code:
Browser(“title”=Gmail.*”).Page(“title:=Gmail.*).Link(“outertext:=Sign out”).Click
If not, add other properties like html id or class for “Link” class.
It should work
Hi Anshoo,
Good Article for Automating Gmail.
Regards
Mahesh
Hi Anshoo,
This is satish working as a quality engineer in s/w organization..i am purely into manual testing..i have a keen interest to shift into automation side.. i have very basic knowledge in QTP where i am aware of developing very small scripts covered all concepts..can you please guide me how to approach further inorder to gain more knowledge in QTP(from basic to advanced)
If you have any documents/link then please email to satish.btech2210@gmail.com
Thanks in advance,
Satish
how to see emails in gmail which comes i particular date
Hi Anshoo,
please tell how to test emails in gmail which comes in particular date like 09-12-2010
Hi Anshoo
Thanks for your great effort to help Qtp learners like me.I tried to automate gmail and yahoo pages but qtp recognises them as winobjects.Please advice me what to do.Relevant codes site is rcognised as a browser but gmail and yahoo are recognised as windows object.Please guide me what to do.
Thanks
Aruna
Aruna,
Is the Web add-in loaded? Are you using IE, and was IE launched “after” QTP?
The gmail compose button, I believe due to its custom build, is almost impossible to script. I tried so many different approach, including the one provided in this post. And all of them failed. Arun, I hope you can show me some light on this.
WebElement(“innertext:=Compose Mail”, “html tag:=SPAN”) these with many additional properties unable to detect QTP to select the compose button.
Thanks.
Mark
Mark: Try this:
Setting.WebPackage("ReplayType") = 2 Browser("title:=Gmail.*").WebElement("innertext:=Compose Mail", "class:=J-K-I-Jz").Click Setting.WebPackage("ReplayType") = 1Hi Anshoo,
Thanks for prompt reply! And it did the trick!!
Can you please explain theses two lines:
Setting.WebPackage("ReplayType") = 2 Setting.WebPackage("ReplayType") = 1I did try the
WebElement("innertext:=Compose Mail", "class:=J-K-I-Jz")before without any luck.
Mark
Mark,
Changing the replay type changes the way events occur on the AUT. Tarun has written an article about it here: http://knowledgeinbox.com/articles/qtp/settings/when-to-change-qtp-web-replaytype-setting/
Mark,
Those 2 statements change the Replay type for Web applications from Browser to Mouse and vice-verse. Tarun has written an article regarding this topic which you can find here.
Hi Anshoo,
Its me again. I tried to use the same compose button concept you showed me for two other undetectable button/link: Attach a file and Send.
It works fine for Attach, but failed on Send.
Also I am having trouble to script the file attachment Dialog window, several trial & error failed. The details code below:
SystemUtil.Run"iexplore.exe","gmail.com" Browser("title:=Gmail.*").Page("title:=Gmail.*").WebEdit("name:=Email").Set "id" Browser("title:=Gmail.*").Page("title:=Gmail.*").WebEdit("name:=Passwd").Setsecure "pass" Browser("title:=Gmail.*").Page("title:=Gmail.*").WebButton("name:=Sign in").click 'mouse click on compose button Setting.WebPackage("ReplayType") = 2 Browser("title:=Gmail.*").WebElement("innertext:=Compose Mail", "class:=J-K-I-Jz").Click Setting.WebPackage("ReplayType") = 1 Browser("title:=Gmail.*").Page("title:=Gmail.*").WebEdit("name:=to").Set "abc@xyz.com" Browser("title:=Gmail.*").Page("title:=Gmail.*").WebEdit("name:=subject").Set "Gmail Automation" Set objEdit= Browser("title:=Gmail.*").Page("title:=Gmail.*").WebElement("html tag:=BODY", "html id:=:.*") objEdit.Object.innertext="Testing gmail login, compose, file attach, send and sign out by using QTP-DP" 'mouse click on Attach a file Setting.WebPackage("ReplayType") = 2 Browser("title:=Gmail.*").Page("title:=Gmail.*").WebElement("html tag:=OBJECT","html id:=FLASH_UPLOADER_1").Click Setting.WebPackage("ReplayType") = 1 Wait(2) 'the following 2 lines are not working Browser("title:=Gmail.*").Dialog("micClass:=Dialog").WinEdit("attached text:=File &name:").Set "c:\123.txt" Browser("title:=Gmail.*").Dialog("micClass:=Dialog").WinButton("Open").Click Wait (5) 'mouse click on Send (its not working) Setting.WebPackage("ReplayType") = 2 Browser("title:=Gmail.*").Page("title:=Gmail.*").WebElement("innertext:=Send", "class:=J-K-I-Jz").Click Setting.WebPackage("ReplayType") = 1 Browser("title:=Gmail.*").Page("title:=Gmail.*").Link("innertext:=Sign out", "html id:=:.*").Click Browser("title:=Gmail.*").CloseAllTabsI hope you can provide a solution for those two problems. Also would appreciate if you can suggest any script optimization.
BTW, I am learning QTP from earlier this month, and undoubtedly this is one of the best learning site I came across! Keep up the good work.
Regards,
Mark
Mark,
There you go:
With Browser("title:=Gmail.*") .Dialog("micClass:=Dialog").WinEdit("attached text:=File &name:", "index:=0").Type "c:\123.txt" .Dialog("micClass:=Dialog").WinButton("text:=&Open").Click Setting.WebPackage("ReplayType") = 2 .WebElement("innertext:=Send", "index:=0").Click Setting.WebPackage("ReplayType") = 1 End WithHi anshoo,
suppose i want to search MINU in google.com .upto i find this file i have to search…
how to write a script for this…
Can u suggest me some ans.
Thanks
Hi Anshu,
While executing the below mentioned code on QTP9.2 , it is showing “General Run Error” on line “18″ — “Set ccCount = Browser(“name:=.*”).Page(“Title:=.*”).childobjects(oCheck)”
Please could you help me to resolve the issue
SystemUtil.Run “iexplore.exe” , “www.gmail.com”
Browser(“name:=.*”).Page(“Title:=.*”).WebEdit(“Name:=Email”).set “om.gaurav”
Browser(“name:=.*”).Page(“Title:=.*”).WebEdit(“Name:=Passwd”).Setsecure “”
Browser(“name:=.*”).Page(“Title:=.*”).WebButton(“Value:=Sign in”).click
Browser(“name:=.*”).Page(“Title:=.*”).sync
Set oCheck= Description.Create ()
oCheck(“htmltag”).value = “Input”
oCheck(“type”).value = “checkbox”
MyTotalCheckBox = 0
Looping = “Y”
Do while Looping = “Y”
Set olderlink = Browser(“name:=.*”).Page(“Title:=.*”).link(“Outertext:=Older.*”,”index:=0″)
Set ccCount = Browser(“name:=.*”).Page(“Title:=.*”).childobjects(oCheck)
MyTotalCheckBox = MyTotalCheckBox + ccCount.count
if olderlink.exist(1) Then
Looping = “Y”
olderlink.click
else
Looping = “N”
End if
Loop
Browser(“Name:=.*”).Close
Print “Number of Emails in Your Inbox are” & MyTotalCheckBox
I try to automatize the access to the Gmail index box. The code provided above is working fine for log on on the gmail.
I have problem when i try to access the firs e-mail for example from the inbox. If i try to record the click on the e-mail using QTP 11 the nothing happen (the click in not recognize).
If i try the same but using descriptive approach i receive the error message that the “WebTable” element is not recognized.
If i try to retrieve the name of the “WebTable” using this line: web_table_name1 = browser(“creationtime:=”& icount-1).page(“micclass:=Page”).Frame(“micclass:=Frame”,”index:=0″).WebTable(“micclass:=WebTable”).getroproperty(“name”)
I receive the error that WebElemet is not recognized.
Hi Cosmin,
Did you checked my scripts from comment: 47?
http://relevantcodes.com/automating-gmail-with-qtp/#comment-14268
Thanks.
hi Anshoo,
ould you please help me in automating safari and chrome. Is there any way in qtp to automate them?
Thanks in advance!!!!
I must be missing a very basic thing here:
I am simply trying to log out from GMail, and using
Browser(“title:=Gmail.*”).Page(“micclass:=Page”).Link(“innertext:=Sign Out”).Click
But QTP 11 end up saying : The “[ Link ]” object’s description matches more than one of the objects currently displayed in your application. Add additional properties to the object description in order to uniquely identify the object.
Any suggestions!
Hi Anshoo,
how did you manage to use index:=0 in the following statement, i mean how do we arrive to using index:=0 for this?
sText = Browser(“title:=Gmail.*”).Page(“title:=Gmail.*”)_
.WebElement(“innertext:=You are currently using.*of your.*”, “index:=0″)_
.GetROProperty(“innertext”)
Thanks
Hi Anshoo…….
first of all I say thanks to you……this is very useful to me…….and u have provided very useful informaion on gmail application…….
thank uuuu
Hi Anshoo,
I’m unable to click on ‘Compose Mail’ button, I tried the below code.
Browser(“title:=Gmail.*”).WebElement(“innertext:=Compose Mail”, “class:=J-K-I-Jz”).Click
Regards,
Avinash
hi
anshoo,
every thing is fine but i have a scenario :
select spam mails and delete all spam mails
how will do that ??
Hi Anshoo,
I have an application in which I v to login and submit at specific time , I v created the script for that, but now my problem is I want run the script at specific time from schedule task, I v script to open QTp automatically through command prompt.
My question 1. I want to open command prompt at specific time.
2. On command prompt I want to call script to launch qtp. (I can enter it manually and it’s running successfully)
Dhiraj: You can create an AOM file that can do it. See here: http://motevich.blogspot.com/2008/04/how-to-run-qtp-test-from-command-line.html
This file can be called from a scheduled task, that will run the test from cmdline.
What is the code if you want to read all emails in the gmail account one by one and to copy the sender mail id in to datadable and retrive in to excel
What is the code if you want to read all unread emails in the gmail account one by one and to copy the sender mail id in to datadable and retrive in to excel
I am trying to use checkpoints to validate data for contacts in the contact page for gmail. But the values are not getting recongised and it also does not recognise contact button or any contacts on the page. I am new to QTP too. Can you please help me out
Ashy, as sent to your mailbox:
With Browser("title:=Gmail.*") .WebElement("html tag:=DIV", "html id:=:ra").WebElement("innertext:=Contacts", "class:=is").Click With .WebTable("html id:=:18a") If .Exist(5) Then iRow = .GetRowWithCellText("John Smith") '<--- insert name of a contact here For iCol = 1 To .GetROProperty("cols") Print .GetCellData(iRow, iCol) Next End If End With End WithIs there anyway to automate “validating the content of the opened email item”?
Thanks in Advance…
Currently we are fetching the content of the email using child objects of Frame.
Hi,
How to continue the statements in QTP?
i.e.,” HTMLResultMessage objHTMLResultFile,”Check the Request category list items “,”Items ” &strReqCategory1& “, “&strReqCategory2&”, “&strReqCategory3&”, “&strReqCategory4&”, ”
&strReqCategory5&”, “&strReqCategory6&”, “&strReqCategory7&”, “&strReqCategory8&”, “&strReqCategory9&”, “&strReqCategory10&”, “strReqCategory11
&”, “&strReqCategory12&”, “&strReqCategory13&”, “&strReqCategory14&”, “&strReqCategory15&”, “strReqCategory16& ” are present in the list”,”Pass” ”
How to write this code in next line in QTP instead of writing it continously?
Hi Anshoo,
Currently i am working in manual testing and want to move from manual testing to QTP automation testing.
Could you please provide me some of the start-up learning document in my email id ashi.gkp@gmail.com ?
Thanks
Hi Anshoo,
I have lotus Domino where it doesnt show the number of mail in inbox or unread mail in inbox.
I want to automate to read the no of mails by fetching the subjects of the mail from inbox.
Could you please give me some idea.
I have tried by WebTable property but its showing the result of the portion that is visible not showing the ones under that.
If you want i can send you the screenshots..
Sourish, you can use ChildObjects to match the properties of the unread mails to retrieve the count.
hi all,
i hv 1 dbt, actually my application sends a confirmation mail or some respond mail to customer personal id or customer company email id. i need to chk both mails. can any one help me out to this issue.. Thanks in advance
Hi Anshoo,
While i try to login to Gmail . I am not able to identify the error : ” The user name and password is incorrect. ? ”
I have used the below script .. When i get the error as Enter the password it is executing the respective loop . But when i get the above error message it is not executing the respective loop
Script
Dim a
Set iobjec=createobject(“Internetexplorer.Application”)
iobjec.visible=true
iobjec.navigate “www.gmail.com”
with Browser(“title:=Gmail: Email from Google”).Page(“title:=Gmail: Email from Google”)
.webedit(“html id:=Email”).set “dfadfdfsafad@gmail.com”
.webedit(“html id:=Passwd”).setsecure crypt.encrypt(“dsfsdfwrewaasd”)
.webbutton(“html id:=signIn”).click
‘ *********************** the below loop works *************
If Browser(“title:=Gmail: Email from Google”).Page(“title:=Gmail: Email from Google”).image(“alt:=Visual verification”).exist Then
Msgbox ” Enter the Visual verification text”
wait(5)
End If
‘ ****************** the below loop also works *************************
If Browser(“title:=Gmail: Email from Google”).Page(“title:=Gmail: Email from Google”).WebElement(“innertext:=Enter your password.”).Exist Then
msgbox (“Incorrect Login”)
.webedit(“html id:=Email”).set “qtpt@gmail.com”
.webedit(“html id:=Passwd”).setsecure crypt.encrypt(“dgdfsdfsdsds”)
wait(2)
.webbutton(“html id:=signIn”).click
‘ ************************ This loop does not work **************************
Elseif Browser(“title:=Gmail: Email from Google”).Page(“title:=Gmail: Email from Google”).WebElement(“innertext:=The username or password you entered is incorrect. ?”).Exist then
msgbox (“Incorrect Login”)
.webedit(“html id:=Email”).set “qtptes@gmail.com”
.webedit(“html id:=Passwd”).setsecure crypt.encrypt(“dfsdfsdfdf”)
wait(10)
.webbutton(“html id:=signIn”).click
else
reporter.reportevent 0,”Verify Login “,” Test Pass”
End If
end with
Try this to identify the error:
If Browser("title:=Gmail.*").WebElement("class:=errormsg").Exist(5) Then Reporter.ReportEvent micWarning, "Error", Browser("title:=Gmail.*").WebElement("class:=errormsg").GetROProperty("innertext") End IfHi Anshoo,
I am krishna,I need u r help.I am trying to perform click operation on compose functionality in gmail, qtp identifying the compose functionality but not performing click operation so i tried to use senkeys method still no use could u plz have a look on my code below and plz give an idea to run my script successfully.
code for compose functionality in GMAIL..
datatable.Import(“C:\login.xls”)
Browser(“title:=Gmail”).Page(“micclass:=page”).webelement( “innertext:=COMPOSE”,”width:=115″).click
wait(6)
set WshShell = CreateObject(“WScript.Shell”)
wshshell.sendkeys “{ENTER}”
Browser(“title:=Gmail”).Page(“micclass:=page”).WebEdit(“name:=to”).Set datatable(“mail_id”,1)
Browser(“title:=Gmail”).Page(“micclass:=page”).WebEdit(“name:=Subject”).Set datatatable(subject,”1″)
Browser(“title:=Gmail”).Page(“micclass:=page”).WebElement(“htmltag:=BODY”).Set datatable(body,”1″)
Browser(“title:=Gmail”).Page(“micclass:=page”).WebElement(“innertext:=Send”).Click
pls try this link.. it might work
Browser(“title:=Gmail – Inbox”).Page(“title:=Gmail – Inbox”).link(“text:=Compose Mail”,”html tag:=A”).Click
Krish,
Change the ReplayType and try to click:
Setting.WebPackage("ReplayType") = 2 'click Setting.WebPackage("ReplayType") = 1Signout Class name is Changed:
Browser(“title:=Gmail.*”).Page(“micclass:=Page”).Link(“innertext:=Sign Out”, “class:=gb4″).Click
With Browser(“title:=Gmail.*”).Page(“title:=Gmail.*”)
If .Link(“innertext:=Compose Mail”,”html tag:=A”).Exist(10) Then
.Link(“innertext:=Compose Mail”,”html tag:=A”).Click 1,1,micLeftBtn
If .WebEdit(“name:=to”).Exist(10) Then
.WebEdit(“name:=to”).Set “byzoor@gmail.com”
If .WebEdit(“name:=subject”).Exist(10) Then
.WebEdit(“name:=subject”).Set “Test Mail”
Setting.WebPackage(“ReplayType”) = 2
If .WebButton(“name:=Send”, “html tag:=INPUT”, “index:=0″).Exist(10) Then
.WebButton(“name:=Send”, “html tag:=INPUT”, “index:=0″).Click 1,1,micLeftBtn
.Sync
Else
MsgBox( “Send button Not found”)
End If
Setting.WebPackage(“ReplayType”) = 1
Else
MsgBox( “Subject text box Not found”)
End If
Else
MsgBox( “To text box not found”)
End if
Else
MsgBox( “Compose Mail link not found”)
End If
End With
Hi Anshoo,
This is krish,could u plz help me how to write a script for deleting mails in gmail.Qtp identifying the checkbox as a webelement in this case so plz give me an idea.
Thank you,
Regards,
krish
Krish, you can use the following line of code to select an email in Gmail:
Browser("title:=Gmail.*").WebTable("class:=F cf zt").WebElement("class:=T-Jo-auh", "index:=0").Click Browser("title:=Gmail.*").WebTable("class:=F cf zt").WebElement("class:=T-Jo-auh", "index:=1").Clickthank you..i will try it then getback to u if i have any problem with code..
hi,
how to click the image older emails in standard view.i.e if i want to see 60th mail then i should click on “>” image from standard view, how we can achive this using qtp descriptive programming.
Hi anshoo,
The above code (reading email) is not working.Itied to execute in my machine.getting message like
“The statement contains one or more invalid function arguments.
Line (5): “.ChildItem(iRow, 3, “WebElement”, 0).Click”. ”
could u plz check out.
Thank you,
regards,
krish
write test script in dp below scenario:
1.launch google site,
2.get all links in google site,
3.apply spell check on every link name,
4.close google site
Hi, Ashoo
I am trying to get number of total e-mails in Inbox (appeared as “1–8 of 8″ in top right corner of e-mail) and using this line as you suggested:
sText = Browser(“title:=Gmail.*”).Page(“title:=Gmail.*”).WebElement(“innertext:=\d+-\d+ of \d+”, “index:=0″).GetROProperty(“innertext”)
I am getting error: Can not recognize WebElement…
Could you please
Sorry, my previous post was not completed. So the question is : how to troubleshoot such error (when QTP can not read the text from web page) ? Thanks
You are welcome, Anshoo
:)
Hi Anshoo,
My question is if i have many links on the web page such as 1,2,3,4…………. and so on then each time i have to manually click on these links. Suppose my QTP script is
Browser(“Browser”).Page(“page”).Link(“2″).Click
Browser(“Browser”).Page(“page”).Link(“3″).Click
….
.
.
.
.
.
And so on .
Instead of recoding these link each time i want to use regular expression in the Object repository on the of the links.
Hope this explain my question.
Thanks for response.
Regards,
Anu
How about this:
For ix = 1 to 10 Browser(“Browser”).Page(“page”).Link(“″ & ix).Click NextHi Anshoo,
It is working fine for first link but when it navigates to other link error massage display saying “Link object was not foumd in the object repository.”
Regards,
Anu
You will have to navigate back to the page where the link object exists..
Hey anshoo,
It is not working. Please let me know the solution
Kishore,
Instead of using the Regex in the inline description, you will have to use it directly in the OR instead. Also, you can move all objects under the Frame to under the Page object.
In other words, your hierarchy at the moment is:
Browser
– Page
– Frame
– Link (Sign Out)
When you move the object under page, the hierarchy becomes:
Browser
– Page
– Frame
– Link (Sign Out)
I would still suggest to use the ReGex for Frame directly in the OR.
Hi Anshoo,
Thanks for you reply. It is working now. But if the another framename is starting with ‘c’, it will not work. I,e. The singout link is under a frame which starts witj ‘c’ and compose mail link is under a different frame which also starts with ‘c’. In this case the we get an error if we use the regular expression ‘c.*” for two objects.
Now my question, can we skip this frame object while click on a web link.
I have used the following, but did n’t work out.
1. Browser(“title:=Gmail.*).Page(“title:=Gamil.*).Link(“innertext:=Compose Mail”).Click -9999, -9999
2. Browser(“title:=Gmail.*).Page(“title:=Gamil.*).Link(“innertext:=Compose Mail”, “html id :=:rd).Click -9999, -9999
3. Browser(“title:=Gmail.*).Page(“title:=Gamil.*).Link(“innertext:=Compose Mail”, “x:=33″, “y:=109″).Click -9999, -9999
Note: I am using descriptive progamming and i didn’t store the objects in OR. However i spied these links but i didn’t get any ordinal poperties such as index.
So, can you guide me how to click on links in a page independent of Frames. if you give exact one liner scipts(Gmail signout, gmail compose mail code lines) it would be very helpful for me.
In case if frames needs to be used then how to deal with those when name starts with the same letter.
Thanks
kishore
Yes. You can also skip the Page object.
Notice the title description for your page object. It is Gamil, instead of GMail. Try this:
Browser("title:=Gmail.*").WebElement("html id:=:rd").Clickopen the object repository and use the “Navigate and Learn” Function, set the filter to select Frame and Link type of objects.4 Frames can be found and only one contains the “Sign out” link. Comparing all the properties of the frames, the html id is different.So, following is usable:
Browser(“title:=Gmail.*”).Page(“micclass:=Page”).Frame(“html id:=canvas_frame”).Link(“innertext:=Sign out”).Click
I never thought I have to struggle 12 hrs to automate ‘compose mail’ functionality in gmail. But still I am unable to execute it successfully. I have been struggling to identify the objects of ‘compose mail link”, “To text box”, “subject text box”, “send button”. I can understand it is a simple issue but in real I am struggling,
The code i am using.
‘*****************************************************
If Browser(“title:=Gmail.*”).Page(“title:=Gmail.*”).WebElement(“innertext:=Compose Mail”, “html id:=:rd”, “html tag:=B”).Exist Then
Browser(“title:=Gmail.*”).Page(“title:=Gmail.*”).WebElement(“innertext:=Compose Mail”, “html id:=:rd”, “html tag:=B”).Click -9999, -9999
Browser(“title:=Gmail.*”).Page(“title:=Gmail.*”).Sync
If Browser(“title:=Gmail.*”).Page(“title:=Gmail.*”).WebEdit(“name:=to”, “class:=dK nr l1″, “rows:=2″).Exist Then
Browser(“title:=Gmail.*”).Page(“title:=Gmail.*”).WebEdit(“name:=to”, “class:=dK nr l1″, “rows:=2″).Set ” ”
If Browser(“title:=Gmail.*”).Page(“title:=Gmail.*”).WebEdit(“name:=subject”).Exist Then
Browser(“title:=Gmail.*”).Page(“title:=Gmail.*”).WebEdit(“name:=subject”).Set “hi”
If Browser(“title:=Gmail.*”).Page(“title:=Gmail.*”).WebButton(“name:=Send”).Exist Then
Browser(“title:=Gmail.*”).Page(“title:=Gmail.*”).WebButton(“name:=Send”).Click -9999, -9999
Browser(“title:=Gmail.*”).Page(“title:=Gmail.*”).Sync
Else
MsgBox( “Send button Not found”)
End If
Else
MsgBox( ” Subject text box Not found”)
End If
Else
MsgBox( “To text box not found”)
End if
Else
MsgBox( “Compose Mail link not found”)
End If
‘***************************************************
In some runs, some of the objects are being identified by QTP and in the next run same objects are not being identified.
I thought i would use Object repositary to store the objects and get them identified. But the above mentioned objects are lying under frames whose name starts with ‘c’. So i cant use c.* for all the frames.
Note: Before you suggest any code, please run it once on gmail and if it is passing then only put down here. Otherwise i end up loosing more time in implementing your code.
In some posts i read use the below to click on compose mail
Browser(“title:=Gmail.*”).WebElement(“html id:=:rd”).Click
but i didn’t work
Thanks,
kishore
PS. I just tried the following code and it works:
Browser("title:=Gmail.*").WebElement("html id:=:rd").Clickand this works for ‘to’ and ‘subject’ fields for me:
With Browser("title:=Gmail.*") .WebEdit("html id:=:14d").Set "to" .WebEdit("html id:=:14a").Set "subject" End WithNote: Not all of us have the bandwidth to execute every bit of code before suggesting something. Not all solutions offered here are 100% proof, but 100% free. Sometimes, a solution works in one case, but fails in another. Moreover, regardless of how busy everyone is, they are still trying to put an effort to help each other here. If you feel considering a solution will waste your time, please don’t consider it. We just want to help you Kishore, not waste your time.
Hi Anshoo,
Thanks for your reply. For some reason, the code you suggested is not working. It is failing to identify the compose mail link(What a bad day at work).
<>, i accept that, but my comments came from the frustration. I tryly appreciate the ppl who tries to help others.
Thanks
kishore
No worries :)
Btw, the code that I gave you, I tested before posting here. It certainly works for me and looking at the HTML structure, the Compose Mail link has an HTML ID associated with it, which is generally a unique value. Therefore, we do not need any other identification properties if we have the ID of the object. I saw your code, there are a few changed I have made to it:
With Browser("title:=Gmail.*").Page("title:=Gmail.*") If .WebElement("innertext:=Compose Mail", "html tag:=SPAN").Exist(10) Then .WebElement("innertext:=Compose Mail", "html tag:=SPAN").Click If .WebEdit("name:=to").Exist(10) Then .WebEdit("name:=to").Set "" If .WebEdit("name:=subject").Exist(10) Then .WebEdit("name:=subject").Set "hi" Setting.WebPackage("ReplayType") = 2 If .WebElement("innertext:=Send", "html tag:=B", "index:=0").Exist(10) Then .WebElement("innertext:=Send", "html tag:=B", "index:=0").Click .Sync Else MsgBox( "Send button Not found") End If Setting.WebPackage("ReplayType") = 1 Else MsgBox( "Subject text box Not found") End If Else MsgBox( "To text box not found") End if Else MsgBox( "Compose Mail link not found") End If End WithHi Anshoo,
Thank you very much for the help. It is working now(atlast). Yesterday i tried with different properties(for all the objects),
but it didn’t work. Is there any standard procedure to find certian objects with certain properties? I mean,
if need to find a link is there any standard properties using which it will be identified?
Why my code didn’t work eventhough i’ve provided losts of properties for each object.
I think everytime i am using browser(“”).Page(“”) code. Will it make any difference as you
used simple WITH statement.
Once i again thank you very much for your help.
Thanks
kishore
The
Withstatement only helps compartmentalize your code. There is no other use besides that. Instead of writing this:Browser("Google").Page("Google").WebEdit("q").Highlight Browser("Google").Page("Google").Link("Images").Highlight Browser("Google").Page("Google").Link("Videos").Highlight Browser("Google").Page("Google").Link("Maps").HighlightYou can simply write:
With Browser("Google").Page("Google") .WebEdit("q").Highlight .Link("Images").Highlight .Link("Videos").Highlight .Link("Maps").Highlight End WithThis makes it easier to follow the code. Also, when changing it, you only have to change it once for all related objects.
Thanks Anshoo again. After some minor modifications of your suggested script, I came up with the following script…and its works like a charm. I am giving the full script, as I think for many new comer in QTP, this is a big challenge.
SystemUtil.Run"iexplore.exe","gmail.com" 'Sign in Browser("title:=Gmail.*").Page("title:=Gmail.*").WebEdit("name:=Email").Set "xyz" Browser("title:=Gmail.*").Page("title:=Gmail.*").WebEdit("name:=Passwd").Set "abc" Browser("title:=Gmail.*").Page("title:=Gmail.*").WebButton("name:=Sign in").click 'Mouse click on compose button Setting.WebPackage("ReplayType") = 2 Browser("title:=Gmail.*").WebElement("innertext:=Compose Mail", "class:=J-K-I-Jz").Click Setting.WebPackage("ReplayType") = 1 Browser("title:=Gmail.*").Page("title:=Gmail.*").WebEdit("name:=to").Set "xyz@gmail.com" Browser("title:=Gmail.*").Page("title:=Gmail.*").WebEdit("name:=subject").Set "Gmail Automation" 'Inserting text on body frame object Set objEdit= Browser("title:=Gmail.*").Page("title:=Gmail.*").WebElement("html tag:=BODY", "html id:=:.*") objEdit.Object.innertext="Testing gmail login, compose, file attach, send and sign out by using QTP-DP" 'Mouse click on Attach a file Setting.WebPackage("ReplayType") = 2 Browser("title:=Gmail.*").Page("title:=Gmail.*").WebElement("html id:=FLASH_UPLOADER_1").Click Setting.WebPackage("ReplayType") = 1 Wait(2) 'File attach Dialog("nativeclass:=#32770").WinEdit("attached text:=File &name:", "index:=0").Type "c:\123.txt" Dialog("nativeclass:=#32770").WinButton("text:=&Open").Click Wait(10) 'Send Mail Setting.WebPackage("ReplayType") = 2 Browser("title:=Gmail.*").Page("title:=Gmail.*").WebElement("innertext:=Send", "index:=0").Click Setting.WebPackage("ReplayType") = 1 'Sign Out from Gmail Browser("title:=Gmail.*").Page("title:=Gmail.*").Link("innertext:=Sign out", "html id:=:.*").Click Browser("title:=Gmail.*").CloseAllTabsOne more question for you, after file attachment, before clicking on Send, we have to give time to upload, and if we don’t know the file size, its an uncertain factor. Any suggestion how to deal this issue generally?
Thanks for all your time my friend.
Mark, you can use the following code to loop until the file uploads:
While Browser("title:=Gmail.*").WebElement("class:=dQ").Exist(0) Wait(1) Wend{ 1 trackback }