There are many tutorials 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:

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
'Updated 03/12/2012 Set oRegExp = New RegExp oRegExp.Global = True oRegExp.Pattern = "\d+" Set oMatches = oRegExp.Execute(sLink) 'oMatches(0) = 3 iEmails = oMatches(0) If oMatches.Count = 2 Then iEmails = iEmails & "" & oMatches(1) 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:

Retrieve ’1 – 4 of 4′
'Updated 03/15/2012 sText = Browser("title:=Gmail.*").Page("title:=Gmail.*")_ .WebElement("innertext:=\d+–\d+ of \d+.*", "index:=0").GetROProperty("innertext") 'Alternate: sText = Browser("title:=Gmail.*").Page("title:=Gmail.*")_ .WebElement("class:=J-J5-Ji amH J-JN-I").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
'Updated 03/12/2012 Set oRegExp = New RegExp oRegExp.Global = True oRegExp.Pattern = "of .*" Set oMatches = oRegExp.Execute(sText) sMatch = oMatches(oMatches.Count - 1) oRegExp.Pattern = "\d+" Set oMatches = oRegExp.Execute(sMatch) iEmails = oMatches(0) If oMatches.Count = 2 Then iEmails = iEmails & "" & oMatches(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:

Retrieve ‘You are currently using 0 MB (0%) of your 7430 MB.’
'Updated 03/15/2012 sText = Browser("title:=Gmail.*").Page("title:=Gmail.*")_ .WebElement("innertext:=.*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, "Using")(1)) iSpace = Split(iSpace, " ")(0) '0 Print iSpace
RegExp
'Updated 03/12/2012 Set oRegExp = New RegExp oRegExp.Pattern = "\d+ MB" 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:

'Updated 03/12/2012 '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") Setting.WebPackage("ReplayType") = 2 .ChildItem(iRow, 5, "WebElement", 0).Click Setting.WebPackage("ReplayType") = 1 End With
When the row is clicked, the Email is opened for reading:

Compose
This can be tricky. Breaking down each component below:
Clicking Compose
Setting.WebPackage("ReplayType") = 2 Browser("title:=Gmail.*").WebElement("innertext:=COMPOSE", "index:=1").Click Setting.WebPackage("ReplayType") = 1
Recipient, Subject, Body
With Browser("title:=Gmail.*") .WebEdit("html id:=:1b6").Set "test@test.com" 'Recipient .WebEdit("html id:=:1c9").Set "Subject" 'Subject .WebElement("html id:=:1cl", "index:=1").Object.innerText = "Message Body" 'Body End With
Click Send
Setting.WebPackage("ReplayType") = 2 Browser("title:=Gmail.*").WebElement("html id:=:1d3", "index:=1").Click Setting.WebPackage("ReplayType") = 1
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.
{ 131 comments… read them below or add one }
Hi Anshoo,
Is there a issue in QTP 11 identifying Webedit objects in IE 8.0 version.
What is the purpose of using Exist(0) & Exist(15) in the Gmail Login Script?
I need this Gmail scripts .Plz send me to ur script to this mail ID
Thanking u
IN Advance
Nine Maddy: the article is back up.
PS. I have also removed your email to protect your privacy.
Hi Anshoo,
This is Avinash, could u plz help me how to write a script for deleting an email which is already opened in gmail but not from the inbox.
Avinash, this worked for me:
Setting.WebPackage("ReplayType") = 2 Browser("").WebElement("class:= G-atb D E")_ .WebElement("class:=T-I J-J5-Ji nX T-I-ax7 T-I-Js-Gs ar7", "index:=0").Click Setting.WebPackage("ReplayType") = 1Hi Anshu,
I tried with the below code,
Setting.WebPackage(“ReplayType”) = 2
Browser(“title:=Gmail.*”).Page(“micclass:=Page”).WebElement(“class:= G-atb D E”)_
.WebElement(“class:=T-I J-J5-Ji nX T-I-ax7 T-I-Js-Gs ar7″, “index:=0″).Click
Setting.WebPackage(“ReplayType”) = 1
But error prompts saying “Cannot identify the object “[ WebElement ]” (of class WebElement). Verify that this object’s properties match an object currently displayed in your application”
Is tat class values remains constant?
How to identify the delete button has index value as 0 ?
Hi Anshoo
i need script for gmail login screen which means…from top-bottom ie: create a new account button to forgot password button.
which mean that in Create a new account page in Birthday edit fields: month is a drop down menu, day & year are edit fields so wat is the script for it? and in the same page there is gender field which is again an drop down, and a “prove u’r not a robot” which ask us to type the words…for these three scenariors i need script and also for forgot password page. am just qtp beginner kindly help me out
Thanks in advance
Hi,
Could u plz tell me abt the dynamic changes in webtable like height ,width etc. in Gmail.
Whenever i get a mail automatically the height of webtable increases,so which properties can i use instead of height/width etc for the webtable to be static.
thanks,
Divya
Divya, WebTable ‘class’ should work.
Hi Guys,
I have problem with QTP. when running my scripts it will crash due to qtp detects the google chrome browser as windows->winObject when I spy the object. I am using qtp 11. does anyone has a solution for this or a worka roud?
Chris, this should technically only happen if Chrome is running multiple windows or tabs.
Hello Anshoo,
I think this is not the case. but anyways, I was able to get things going. and already reported the issue to HP. hope they’ll fix it ASAP.
Chris, that sounds great. HP has been pretty great this year with support and have been churning out patches/hotfixes quickly. I’m sure you will have a solution soon.
One thing I forgot to ask you was the version of the Chrome browser. I’m sure you’re working on one of the support versions but just curious.
thank u ashoooooo
Any idea to give complete gmail logged in window to user ?????????? instead of giving few apps of it can we give direct login option from our application instead…………????
Hi Anshoo,
I need to compare two images in a website,which has same name,src and html id.But the images are different.could you please help me to identify the two images differently in descriptive programing..please let me know if u need to see the images….
Sourish, you can use a Bitmap checkpoint for these images. Another way is to write your own custom code to do the compare. It cannot be done with VBScript as far as I am aware, so you will have to use DOTNetFactory or VB.NET/C#.NET to accomplish it. You can also use a DLL I had created; can be found here: http://relevantcodes.com/vbscript-compare-2-excel-files/ under the section ‘Update: RelevantCodes.Comparer COM DLL’.
Hi Anshoo
I am facing another challenge related to resd e-mail in Gmail inbox
The code you suggested (see below) does not give me an error, but also does not do anything, i.e. seemes to me click event is not recognized by QTP in my situation
Do you have any suggestion how to resolve?
Thanks
Josepf
————————————-
/This code does not waork on my PC/
With Browser(“title:=Gmail.*”).Page(“micclass:=Page”).WebTable(“class:=F cf zt”)
.ChildItem(iRow, 3, “WebElement”, 0).Click
End With
Joseph, try this:
With Browser("title:=Gmail.*").Page("micclass:=Page").WebTable("class:=F cf zt") Setting.WebPackage("ReplayType") = 2 .ChildItem(iRow, 5, "WebElement", 0).Click Setting.WebPackage("ReplayType") = 1 End WithHi Anshoo
Thanks a lot
Your code from march 15, 2012 related to changing ReplayType to 2 is working. Now QTP recognizing Click event.
Regards
Joseph
Hi Anshoo
The suggested code in your reply N75 does work. the message box displays text “1-22 of 22″, and this is what I need!
Thanks a lot
Joseph
Joseph, this article has been revised to work with the changes made to Gmail. There are 2 ways to do this, please see which one works for you:
'Updated 03/15/2012 sText = Browser("title:=Gmail.*").Page("title:=Gmail.*")_ .WebElement("innertext:=\d+–\d+ of \d+.*", "index:=0").GetROProperty("innertext") 'Alternate: sText = Browser("title:=Gmail.*").Page("title:=Gmail.*")_ .WebElement("html id:=:us", "index:=0").GetROProperty("innertext")Thanks, Anshoo
I tried both methods
First one did work, second one (Alternate) gave me an error.
When I used Object Spy for that element, the html id property was showing as :hr
When I set it that way (see below), it worked
Thanks again for your patience and help
Joseph
=====================
Alternate:
sText = Browser(“title:=Gmail.*”).Page(“title:=Gmail.*”)_
.WebElement(“html id:=:hr”, “index:=0″).GetROProperty(“innertext”)
Joseph, I saw your response and since our ID has changed, I checked my code again and it has indeed changed – and is neither yours or my update in this post. It is something else totally – :ax.
The ‘class’ property remained unchanged after 2 logins and from 2 of my accounts.
.WebElement("class:=J-J5-Ji amH J-JN-I").Thank you, Anshoo
So I will use the ‘class’ property as advised. The common challenge i see in automation GMail functionality: GMail changing properies and appearance pretty frequently and my code need to be updated accordingly. Is there a way to not rely on hardocded properties in QTP code, but rather retrieve current properies of the web page before using it for actions like click, browse, mail compile etc.?
Regards
Joseph
Joseph, in reality, we must update our code when there are such changes in the UI. Generally, it is advisable to work with developers so we know what’s coming up. I have worked on projects where some properties remained unchanged despite changes in UI, for example: HTML_ID.
Fair enough,
Thank you.
Joseph
hello sir,
my project is on single sign on , i need to sign in to gmail facebook simultaneously by my web application from my local host…. i am not able to do it ……….. no clue available for me ……….. please do reply and do a favour……………………………………thank u
Puja, not sure what you mean, log-in simultaneously from local-host? Please clarify.
Hi Anshoo
I’ve also been having the same problems as Joseph. I could not get the following code to work:
sText = Browser(“title:=Gmail.*”).Page(“title:=Gmail.*”).WebElement(“innertext:=\d+-\d+ of \d+”, “index:=0″).GetROProperty(“innertext”)
Apologies if your last comment addressed to Joseph is regarding the above. If your response has nothing to do with this, would you be able to help with my query?
Regards
Melanie, does the following piece of code work:
sText = Browser("title:=Gmail.*").Page("title:=Gmail.*").WebElement("innertext:=\d+–\d+ of \d+.*", "index:=0").GetROProperty("innertext") MsgBox sTextHi again Anshoo
No your suggestion didn’t work unfortunately. I used the following temporary workaround and this worked:
Browser(“title:=G.*”).Page(“title:=G.*”).WebElement(“innerText:=1 .*”,”index:=0″).GetROProperty(“innertext”)
I’ve now found another problem. When performing an email search within Google Mail, I want to find all rows in the dynamic webtable where the subject contains text “Google Alert” emails and delete them. At the moment all I can do is get the 1st row which meets this criteria (using .GetRowWithCellText method) and delete it but I want to delete all other relevant rows.
I tried the following but this didn’t work:
Dim oDesc ‘Description Object
Dim colObject, x
Set oDesc = Description.Create
oDesc( “micclass” ).value = “Link”
oDesc( “innerText” ).value = “Google Alert.*”
oDesc( “innerText” ).regularExpression = True
‘
Set colObject = Browser( “title:=G.*”).Page(“title:=G.*”).WebTable(“class:=th”).ChildObjects( oDesc )
For x = 0 to colObject.Count – 1
‘ MsgBox colObject(x).GetROProperty(“innerText”)
colObject(x).Highlight
Next
Hi, My Dear QTP experts i’m trying to learn Descriptive programing. I create a script for yahoo login and to open inbox, i’m able 2 log in but can’t just write the code to click on inbox and open it, below is my beloved effort to chekc yahoo inbox. Plz plz help me
systemutil.Run”iexplore.exe”,”www.yahoo.com”
browser(“micclass:=browser”).page(“micclass:=page”).WebElement(“micclass:=WebElement”,”html tag:=SPAN”,”innertext:=Mail”).Click
browser(“micclass:=browser”).page(“micclass:=page”).WebEdit(“html id:=username”).Set “username”
browser(“micclass:=browser”).page(“micclass:=page”).WebEdit(“html id:=passwd”).Set “passwd”
browser(“micclass:=browser”).page(“micclass:=page”).WebButton(“html id:=.save”).Click
browser(“micclass:=browser”).page(“micclass:=page”).webElement(“html tag:=EM”,”innertext:=Inbox (878)”,”outertext:=Inbox (878)”).Click
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
Joseph, does the following give you the correct value:
MsgBox Browser("title:=Gmail.*").Page("title:=Gmail.*").WebElement("innertext:=\d+–\d+ of \d+.*", "index:=0").GetROProperty("innertext")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 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
Krish, what is the value for iRow? Is it an integer?
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,
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..
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
Signout Class name is Changed:
Browser(“title:=Gmail.*”).Page(“micclass:=Page”).Link(“innertext:=Sign Out”, “class:=gb4″).Click
Hi 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") = 1Hi 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 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,
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 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,
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?
Is 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.
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 WithWhat 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
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
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.
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’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…….
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,
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
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,
ould you please help me in automating safari and chrome. Is there any way in qtp to automate them?
Thanks in advance!!!!
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 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
Hi 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 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
Am new to qtp .Am facing the same problem., not able to attach file and Send in Gmail.
I have tried the same thing , Replay Type worked for Compose but not working for Send.,Please help me
Veena, try this:
Setting.WebPackage("ReplayType") = 2 Browser("title:=Gmail.*").WebElement("html id:=:z8").Click Browser("title:=Gmail.*").WebElement("class:=T-I J-J5-Ji Bq nS T-I-KE L3").Click Setting.WebPackage("ReplayType") = 1Do either of them work?
Anshoo , its not working.,
I tried with ur Script also , But no luck.
Here am sending the code and error
Please help me in resolving this
Thanq
‘Setting FileName Attach Dialog Box ——-Not Working
Browser(“title:=Gmail.*”).Dialog(“micClass:=Dialog”).WinEdit(“attached text:=File &name:” , “index:=0″).Type “C:\Users\veena\Desktop\Refer.txt”
Browser(“title:=Gmail.*”).Dialog(“micClass:=Dialog”).WinButton(“text:=&Open”).Click
‘Send Button —-Not Working
Setting.WebPackage(“ReplayType”) = 2
Browser(“title:=Gmail.*”).Page(“title:=Gmail.*”).WebElement(“innertext:=Send”,”class:=J-K-I-Jz”, “index:=0″).Click
Setting.WebPackage(“ReplayType”) = 1
For Attachment — it gives the following error
Cannot find the “[ WinEdit ]” object’s parent “[ Dialog ]” (class Dialog). Verify that parent properties match an object currently displayed in your application.
For Send — it gives General Run Error
Hi 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.
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 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?
Hi Anshoo,
please tell how to test emails in gmail which comes in particular date like 09-12-2010
how to see emails in gmail which comes i particular date
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
Hi Anshoo,
Good Article for Automating Gmail.
Regards
Mahesh
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
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/
I am glad some to know some one who really meant to help others!!
God Bless you with more knowlege.
this is the best code & coverage ever I got online….
Thanks a Ton…wonderfull…….
:)
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:
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??
Hello,
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
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 = NothingHi 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
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.
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
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) WendJoseph, that generally means the description we’ve used is incorrect. Google updates mail quite frequently and my article is soon becoming outdated! I will soon spend some time and update it according to the changes made to Gmail.
Melanie, you can use one of the below solutions:
'Updated 03/15/2012 sText = Browser("title:=Gmail.*").Page("title:=Gmail.*")_ .WebElement("innertext:=\d+–\d+ of \d+.*", "index:=0").GetROProperty("innertext") 'Alternate: sText = Browser("title:=Gmail.*").Page("title:=Gmail.*")_ .WebElement("html id:=:us", "index:=0").GetROProperty("innertext")fyi, article has been revised.
For your 2nd query, part of the solution below:
With Browser("title:=Gmail.*").Page("micclass:=Page").WebTable("class:=F cf zt") iRows = .GetROProperty("rows") For ix = 1 to iRows If .GetRowWithCellText("Google Alert", "", ix) Then 'Select Row End If Next End WithHI Anshoo
I liked your Gmail automation qtp progmamming
I m not able to click compose button since it has changed again.
Can you please help out
I have tried hard but not able to solve it out
Thanks in Advance
{ 1 trackback }