Introduction
In this article, we will cover the basics of Description Object and the ChildObjects method. This is a very powerful approach to creating robust automation test suites. It is also a very important principle of Descriptive Programming in QTP.
We will see how we can create an object description with a single property, with multiple properties, by using regular expressions and finally putting all these concepts into their application with the ChildObjects method.
Before we see how it is done, we must first understand the following statement:
Set oDesc = Description.Create
Above, we are using the variable oDesc to create a description of something. Since, oDesc is preceeded by a Set statement, it must be an object reference. Therefore, when the above statement executes, oDesc will become an object reference to a description object. We will use the description object with the ChildObjects method to retrieve object collections. These object collections are nothing but arrays of objects with the exact properties of the description object.
If you are starting with DP, please read the article on Descriptive Programming Concepts on Relevant Codes for a quick walk-through on Descriptive Programming before continuing with this article.
I. Creating a Description Object for a Parent (Browser/Window)
To create an object description for a parent, we will simply use the “Class” of the parent object and add the property-value combination:
Dim oDesc 'Description Object Dim colObject 'Object Collection Set oDesc = Description.Create 'Remember to always use 'micclass' and not 'class name' oDesc( "micclass" ).value = "Browser" 'We used Desktop as the parent here because, the Desktop Object holds all the Windows Set colObject = Desktop.ChildObjects( oDesc )
When the above snippet execute, colObject will contain a collection of all browsers visible on the desktop.
But, since we have done this, how will we know how many browser objects exist on the desktop through code? Also, how will we retrieve their information? The answer is quite simple: colObject contains the necessary information and methods we can use to perform events on our target objects.
'Retrieve # of open browsers MsgBox colObject.Count 'Retrieve Titles of all open browsers For x = 0 to colObject.Count - 1 MsgBox colObject(x).GetROProperty("title") Next
As I mentioned above, colObject is nothing but an array of all objects having the exact same properties as the description object. Therefore, colObject(0) points to the first object in the collection, colObject(1) points to the second object in the collection, and so on. This is demonstrated in the For..Next loop in the snippet above.
II. Creating a Description Object for an Object contained in a Browser/Window
Using the same approach above, we will retrieve collection of all Link objects on a page. Notice here that instead of Desktop, we have used the entire Browser-Page hierarchy. This is because, a link object is present somewhere inside the Page, instead of the desktop :).
Dim oDesc 'Description Object Dim colObject 'Object Collection Set oDesc = Description.Create oDesc( "micclass" ).value = "Link" 'Using the entire Browser-Page hierarchy Set colObject = Browser( "title:=Google").Page("title:=Google").ChildObjects( oDesc )
By executing the snippet above, we will use colObject to perform some events on these objects. Let’s retrieve the number of link objects present in our browser:
'Returns 30
MsgBox colObject.CountThe above example is created for the Google page, and if you want to test it for some other browser, do not forget to change the Browser and Page titles to the correct values.
III. Creating a Description Object for an Object contained in a Browser/Window Using Multiple Properties
If you saw the above example, we created a description object using only the class of the Link object. Now, we will retrieve a more specific object collection. We are going to specify an additional property and narrow down the search results- this is because, even though there can be multiple Link objects on a page, its not necessary that there would be the same number of objects with the text “Hello, I am a Link!”.
This approach helps us retrieve only the objects that we really want for our automation, since having a collection of all objects can be quite cumbersome to work with. Also, if we provide relevant information to our Description Object, QTP will return a narrowed-down collection, which is the easiest to work with. This is similar to how you search Google. If you specify “QTP” in Google Search, you will have a huge array of search results. You can narrow down the search results (and find information faster) if you add “QTP + Browser + DP” instead.
Dim oDesc 'Description Object Dim colObject 'Object Collection Set oDesc = Description.Create oDesc( "micclass" ).value = "Link" 'Additional property- for more focused and controlled collection oDesc( "text" ).value = "Images" Set colObject = Browser( "title:=Google").Page("title:=Google").ChildObjects( oDesc ) Msgbox colObject.Count 'Returns 1
Now, colObject will only contain the Link objects that have the text: Images. Also, if you notice Google page, there is only one link with the Images text. This is a good example of finding the target object dynamically. Suppose, if there were 2 links on the page instead, we would have both of them in our collection colObject. Let’s highlight our found object:
colObject(0).Highlight
Executing the statement above, we will highlight the first object in the collection. I know there is only one object in the collection, but we can make sure by doing this:
For x = 0 to colObject.Count - 1 colObject(x).Highlight Next
IV. Creating a Description Object using WildCards
If we have dynamic objects in our application, then we may not always have the luxury to feed their properties as we have done in the example above. Sometimes, we would need to create dynamic descriptions and retrieve our target objects from resulting (dynamic) collections. I say dynamic collections because at one time, your collection may hold 9 objects, whereas during the next session, it may hold 10.
Dim oDesc 'Description Object Dim colObject 'Object Collection Set oDesc = Description.Create oDesc( "micclass" ).value = "Link" oDesc( "text" ).value = "I.*age.*" 'Images '.regularExpression is 'True' by default oDesc( "text" ).regularExpression = True Set colObject = Browser( "title:=Google").Page("title:=Google").ChildObjects( oDesc )
You may want to read the article on Regular Expressions to better understand how these work in Descriptive Programming.
After executing the snippet above, we will have a collection object with all object that match the regular expression. Let’s see the count of the objects:
'Returns 1 because our supplied pattern only matches with the word: Images
MsgBox colObject.CountLet’s replace the “text” with “ma” instead and see if we still retrieve a collection with a single object:
Dim oDesc 'Description Object Dim colObject 'Object Collection Set oDesc = Description.Create oDesc( "micclass" ).value = "Link" oDesc( "text" ).value = ".*ma.*" 'Images '.regularExpression is 'True' by default oDesc( "text" ).regularExpression = True Set colObject = Browser( "title:=Google").Page("title:=Google").ChildObjects( oDesc )
To see what has changed, let’s execute the following:
'Will return 4
MsgBox colObject.CountIf you do execute the snippet above, the count would be 4. Why is that? To see the new objects in our collection, let’s do this:
For x = 0 to colObject.Count - 1 MsgBox "x:" & x & " || " & colObject(x).GetROProperty("innertext") Next
Below are our outputs:
Interesting, isn’t it? Our description for the text property matched all links that had the letters ma in them.
V. Negating WildCards
Sometimes we have an object description with wildcards in it. Here, we want to turn off the Description Object’s ability to register the description as a regular expression. This is quite simple, and we do it by turning regular expression as False:
Dim oDesc 'Description Object Dim colObject 'Object Collection Set oDesc = Description.Create oDesc( "micclass" ).value = "Link" oDesc( "text" ).value = ".*ma.*" 'Images oDesc( "text" ).regularExpression = False Set colObject = Browser( "title:=Google").Page("title:=Google").ChildObjects( oDesc ) MsgBox colObject.Count 'Returns 0
Now, the above snippet will not identify Images or Maps. Instead, it will only identify objects that have the exact text .*ma.* which really doesn’t exist anywhere on the Google homepage.
VI. Creating a Description Object for Integer-Types
So far, we have only learned various ways to work with description objects using Strings. Here, we will see how they transform into integer-types. Let’s bring up the properties of the Images link again using the Object spy and feed its “x” coordinate to see whether we can find the link:
Dim oDesc 'Description Object Dim colObject 'Object Collection Set oDesc = Description.Create oDesc( "micclass" ).value = "Link" oDesc( "x" ).value = 51 'It should always be 51, not "51". Set colObject = Browser( "title:=Google").Page("title:=Google").ChildObjects( oDesc ) 'Will return 1 MsgBox colObject.Count 'Will return Images For x = 0 to colObject.Count - 1 MsgBox colObject(x).GetROProperty("innertext") Next
Notice that 51 above is not within quotation marks. This should always be the case. Notice when we replace it with a string-type below:
Dim oDesc 'Description Object Dim colObject 'Object Collection Set oDesc = Description.Create oDesc( "micclass" ).value = "Link" oDesc( "x" ).value = "51" Set colObject = Browser( "title:=Google").Page("title:=Google").ChildObjects( oDesc ) MsgBox colObject.Count For x = 0 to colObject.Count - 1 MsgBox colObject(x).GetROProperty("innertext") Next
The collection is an empty one:
So, always remember to treat integers as they are. This always holds true for x, y, abs_x, abs_y.
VII. Building Object hierarchy with ChildObjects
We will use the Browser Object Collection to set a value in a text box to demonstrate this:
Dim oDesc 'Description Object Dim colObject 'Object Collection Set oDesc = Description.Create oDesc( "micclass" ).value = "Browser" oDesc( "title" ).value = "Google" 'Notice we used the Desktop Object again for retrieving Window collection Set colObject = Desktop.ChildObjects( oDesc ) 'Retrieve the count iCount = colObject.Count 'Set value in the WebEdit of the last Window object in the collection For x = 0 to iCount - 1 'Verify if the Browser title equals "Google" If Browser("creationtime:=" & x).GetROProperty("title") = "Google" Then 'Set Description.Create in the search TextBox Browser("creationtime:="&x).Page("micclass:=Page").WebEdit("name:=q").Set "Description.Create" End If Next
When the above snippet executes, we will have the following value set in the Search TextBox in Google HomePage:
I hope this article will help you guys understand the concepts of one of the most important concepts in Descriptive Programming: the Description Object. Thanks for visiting Relevant Codes :)
If you have any questions, please ask them in the comments section. If your information is to be treated as confidential, please use the Contact Form to send me an e-mail instead.

{ 118 comments… read them below or add one }
Hi Anshoo,
The Description object article is very clear with examples.keep up the good work
Regards
Suni
Hi Sunitha,
Can you please send some web based exercises to work on. I am a beginner in QTP. My mail id is charles.vimala@gmail.com.
Thanks,
Charles.
Thanks! :)
Hello Anshoo,
Can you please tell me the difference between vbcr and vbcrlf vbscript constants? In the help file, its mentioned that vbcr gives a carriage return which according to me is Enter key in our keyword and vbcrlf does the same plus it adds linefeed. now what is this linefeed? I have already got the enter command through vbcr so why vbcrlf? Also vbNewline is there?
Regards,
Sangeetha
Hi Sangeetha,
Great question, and to be honest with you, I never use vbCr. However, you raise a good question and to answer it, I am going to recommend you to read the following article: NewLine. It will explain what each means and how they came about.
A linefeed is quite an interesting concept, but before I explain that, I must explain what a carriage does. A carriage just moves one line down from the point where the method is executed. A linefeed enables the cursor to move to the far-left, where you would want it to be, and that’s ideal/common.
vbCrLf resembles that and its easier for beginners to understand what it does. So, even though it does the same thing, its quite easy to comprehend what it would do without much thought.
vbNewLine on the other hand, and I am not too sure here, but I think its platform dependent and it may signify different things in different environments. This is all MSDN says about it: vbNewLine.
Hi,
Can you help me in QTP by providing some practical exercises. I am a beginner. My mailid is charles.vimala@gmail.com.
Thanks,
Charles.
Hi Sangeetha,
Can you please send some good practical exercises on QTP. I am a beginner. My mailid is charles.vimala@gmail.com
Thanks,
Charles.
Hello Anshoo,
Can you please tell me that in the case of array, which approach is better to loop thru the items: For Each loop or a normal for loop? or either can be used?
Also why do LBound and UBound function works fine with the arrays created using Array keyword and not with the arrays declared like Dim A(3). I see that UBound(arr) gives a different answer in these cases.. Can you please explain me why?
Hi Pragya,
I rarely use For..Each Loops. I find it easier and more efficient working with the normal For..Next Loop (you can directly access the element number without using an explicit counter which you would in For..Each). I have also noticed on several occassions that there is a slight performance drop when using For..Each loops. To illustrate, let’s see the example below:
Dim arrArray: ReDim arrArray(9) Dim tStart, x, Element arrArray = Array("a", "b", "c", "d", "e", "f", _ "g", "h", "i", "j") tStart = Timer For Each Element in arrArray Print Element Next Print "For Each: " & Timer - tStart 'I can directly use "x" here 'With For..Each, I would have to use an increment to know which element I am working with tStart = Timer For x = LBound(arrArray) to UBound(arrArray) Print arrArray(x) Next Print "For Next: " & Timer - tStartWhich one gives a better time?
Using the same array above, when I execute the following line, I get 9:
In your case, when you do UBound(A), you should get 3. It should return 3.. Can you please share with me your result as well?
Hi,
Can you explain with the example that what are child object, How should we get this from parent object and where
should we use this?
Thanks,
Alkaa,
Your question can emcompass an entire topic – its that vast. However, to give you a quick idea of how and where we use ChildObjects, let me walk you through a simple scenario:
Suppose you have n number of CheckBoxes on a page, and this number changes depending on your inputs on previous screens. The requirement is to enable them all regardless of the number of CheckBoxes. So, let’s say for Process 1, there are 20 Checkboxes on the page, but for Process 2, this number increases to 40.
This is where ChildObjects can be used, and makes work extremely easy. Since ChildObjects retrieves object collections, we can use it to enable all the CheckBoxes easily. In your library, this is all the code you would have to keep to enable them all:
'Creating a description object for a WebCheckBox Set oCheckBox = Description.Create oCheckBox("micclass").value = "WebCheckBox" 'Object Collection Set colObject = Browser("").Page("").ChildObjects(oCheckBox) 'Looping through the collection and enabling all CheckBoxes For x = 0 to colObject.Count - 1 colObject(x).Set "ON" NextI hope this helps.. If you’re still unclear, we can create a working example too.
Anshoo,
You gave me a good initiative idea about child object. I am understanding from different angles. Kindly clarify my one more issue that….can we use micClass universally in descriptive programing everywhere like with browser, page, text and combo or it is specified only for Browsers? I explored alot but could not get any satisfactory answer. I have big tumor of confusion and questions from long time. Therefore kindly reply.
thanks in advance..
Yes, the micclass identifier can be used with any object, regardless of the application and technology. micclass equals Class Name in Object Spy. Each Object, regardless of the properties it has, also has a class-type identifier, which is defined by micclass.
However, even though each object can be identified using its micclass identifier, you must note that it may not be sufficient to uniquely identify an object. For example, open 2 browsers and execute the following code:
Browser("micclass:=Browser").HighlightIt will result in an error. That is because even though the Class Name was used, it is not enough to identify the correct browser between the 2 open browsers. Thus, you will have to add other properties to make the distinction between the two. Obviously, this would result in the same behavior if there were multiple objects of any class. We would need to use additional properties to identify them uniquely, and using micclass alone will not help.
Good Explaination with examples ,thank you
Glad it helped! :)
Hey there,
I believe my question is related as it deals with child objects. Anyhow here’s my problem.
I’m having a bit of trouble identifying WebEdit objects on a web app I’m testing. The problem is the input box themselves don’t have id’s and the class associated with each is not unique. Also the ordering of them may be different depending on other variables so I cannot use their indexes. However, each input box is a child of a div that does have a unique id. I can’t figure out how to set the value in the input box.
The HTML structure is as follows:
and the following qtp snippet spits out the innerhtml of the first input box:
Browser("").Page("").Frame("").WebElement("html tag:=DIV", "html id:=unique_id_1").GetROProperty("innerhtml")Is there anyway to take that output and cast it to a WebEdit object?
Thanks for any help,
Jason
Jason,
You can wrap your code around:
p r e
/ p r e
(without spaces)
Sorry, I thought the ‘code’ tags would display the HTML structure.. guess not. Let’s try with ‘pre’ tags:
and if that didn’t work:
Hi Jason,
You can try the following:
With Browser("Browser").Page("micclass:=Page") .WebElement("html id:=unique_id_1").WebEdit("class:=non_unique_class").Set "1" .WebElement("html id:=unique_id_2").WebEdit("class:=non_unique_class").Set "2" End Withor:
With Browser("Browser").Page("micclass:=Page") .WebElement("html tag:=DIV", "html id:=unique_id_1").WebEdit("index:=").Set "1" .WebElement("html tag:=DIV", "html id:=unique_id_2").WebEdit("index:=").Set "2" End Withexcellent info, If you have more things to I would very much aprreciate it.
Thanks, Sam. I will try to post a few more such articles in the coming weeks!
Hi,
I have one problem in passing a value to a link object.
I have set of links in a folder frame .. for ex: Test1,Test2,Test3,Test4 .. etc.
While recording, i had selected Test1 link in the folder frame. Test1 has been added to the object repository as a test object.
Test1,Test2,Test3,Test4 are the objects of the class Link.
Now if i want to select Test2 by running the same script .. how?
For that i used msgbox function to allow the user to enter the value of the link.
I got the list of link objects in the folderframe object and i created a loop to check whether the value entered by the user is equal to the value of the link (got it by using child objects method).
Whenever the value entered by the user and the link got it from the application are same, i am trying to pass that value to the link method as mentione below:
Browser(“Login”).Page(“Application”).Frame(“folderFrame”).Link(“Classification”).Click
Classification is the value which is entered by the user.
Let us say user wants to select Link Test2 where as Link Test1 has been selected while recording.
When i execute the above mentioned statement, instead of selecting link Test2, it is selecting Test1(which was selected while recording).
Pls help me in this .. if you are not able to understand, feel free to mail me @ nbabu11@gmail.com
Hi Babu,
If you’re using DP:
For ix = 1 to 4 Browser("Login").Page("Application").Frame("folderFrame").Link("innertext:=Link" & ix).Click NextIf you’re using OR:
For ix = 1 to 4 Browser("Login").Page("Application").Frame("folderFrame").Link("Link" & ix).Click NextHow would you go about only grabbing children that ONLY have numbers in their “innertext”?
Here is what I have so far:
———————————————————————————————————————————————————————
Dim oDesc ‘Description Object
Dim colObject ‘Object Collection
‘Filter web child objects to get only the child under “Account Number”
Set oDesc = Description.Create
oDesc(“micclass”).Value = “Link”
oDesc(“html tag”).Value = “A”
oDesc(“height”).Value = 13
Set colObject = Browser(“micClass:=Browser”).Page(“micClass:=Page”).ChildObjects( oDesc )
‘Retrieve the count
iCount = colObject.Count
————————————————————————————————————————————–
It is returning back 8 children. But I only want to retrieve one child. The other seven children have letters in their “innertext” and teh one child I want only has numbers.
Thanks,
Steve
Hi Steve,
For a description object to incorporate only numeric values, the following ReGex would be applicable to the object’s innertext:
Set oDesc = Description.Create oDesc("micclass").Value = "Link" oDesc("innertext").Value = "\d+"Thanks much Anshoo!
Steve
:)
Your examples are truly useful but I got one question:
If I wanted to use a Description Object to identify certain type of objects on my app screen, but I want to exclude objects, say for example, that have a property with a specific value.
How could I handle this?
Something like:
Set oDesc = Description.Create
oDesc(“micclass”).Value = “Link”
oDesc(“html tag”).Value = “A”
oDesc(“height”).Value 13
That would return Links with html tag = “A” but exclude those links with value = 13.
Thanks!
Hi Israel,
I don’t think this is possible, and you can verify this through Object Repository as well. With constants in such situations, regular expressions are not allowed so I’m not sure how we can create such a description object. I think the only feasible way at present is by using (and negating) objects in the collection through a loop:
For ix = 0 to iCount - 1 If colObject(ix).GetROProperty("height") = 13 Then SkipStep Nextthanks
Hi Anshoo,
Just want to know, if I want to create the description only once and want to use that description in all the tests. How can I do that. Because if there are many tests and I am using descriptive programming then it is becoming a problem. Can you provide some guidance. Is there any possibility to do that using function? if yes, how? Plesae provide some examples.
Thanks in Advance
San
Hi San,
If you would like to only create the Description Object without any properties, you can do it through a function call:
Function DescObject() Set DescObject = Description.Create End FunctionIf the same needs to be done with addition of properties, you can do this:
Function DescObject(sProperty, sValue) Dim oDesc : Set oDesc = Description.Create oDesc(sProperty).Value = sValue Set DescObject = oDesc End Function 'Usage: Set oDesc = DescObject("micclass", "Browser") MsgBox Desktop.ChildObjects(oDesc).CountThe above function can certainly be extended for more properties and values. I hope this helps :)
Hi,
I am using the following code to get child objects:
set EditDesc = Description.Create() EditDesc("automationclassname").Value = "FlexList" Set m_Child = m_target.ChildObjects(EditDesc) msgbox m_Child.Countbut it give me the count of all child items instead of only “FlexList” objects.
I can get the FlexList objects in the collection but why its not working with description.
Can anybody help me out where i am wrong????
Devender, try this:
Set EditDesc = Description.Create EditDesc("micclass").Value = "FlexList" Set m_Child = m_Target.ChildObjects(EditDesc) MsgBox m_Child.CountHi San,
May be Environment variable helps you out to store the collection and retreive in-between the tests.
Anshoo, I am using QTP 9.1
And the problem is that QTP is not able to recognize/identify the devX components like grid, dropdowns, checkboxes etc.
It is recognizing these as IMAGES. And I came to know that it is possible using DotNetFactory feature, but I don’t know how to implement that. Can you please provide some light on this.
Thanx
What add-in is it, San? .NET?
Its very nice article for the beginners…
Thank you Neelakanthan, I’m glad it helped :)
Hi
I have the following 2 questions:
* Is it possible to automate siebel 8.1 using QTP ?
* Is there a way to retrieve all the Parent objects , given the name and type of child object?
Regards,
Pavi
#1. Yes, its possible to automate Siebel 8.1 with QTP. I am currently working with Siebel 8.1 and QTP works quite well; a little slow, but manageable :)
#2. Not sure what you mean? Why would you like to do something like this, especially since its the Child Objects that change and are really dynamic in nature?
Hi, Anshoo,
I cannot use ChildObjects for finding a WebElement. Following is the example
For example, we have a html:
I prepare to use the following script for identify the text named “DP is cool!”.
Set objDesc= Description.Create() objDesc ("micclass").value = "WebElement" 'objDesc ("html tag").value = "B" objDesc ("innertext").value = "DP is cool!" Set testPage = Browser("name:=WebTest").Page("title:=WebTest") set objTesting = testPage.ChildObjects(objDesc) msgbox objTesting.countThe result always be zero. That means QTP cannot find it. Why?
Maybe I can use the
.Object.getElementsByTagNameto find it, but I still wonder to know why I cannot find it by the above method.Do you have any idea?
Thank you very much in advance.
Regards,
Dennis
Dennis,
Remember to use the “\” backslash for the ReGex meta-character:
Set objDesc= Description.Create() objDesc ("micclass").value = "WebElement" objDesc ("html tag").value = "B" objDesc ("innertext").value = "DP is cool\!" Set testPage = Browser("creationtime:=0").Page("micclass:=Page") set objTesting = testPage.ChildObjects(objDesc) MsgBox objTesting.Count 'Gives 1It seems this blog will parse the html tag automatically even I include it in “pre” tag.
It should be
[html][title]WebTest[/title][body][b]DP is cool![/b][/body][/html]Hi ,
Can anyone please help me out with How to maximize browser in Virtual machine.
I tried with Window().maximize … It works on the local machine .. but not on Virtual..
Also tried with hwnd property … But it never seems to work.
Please help me out.
Ranjana,
Try this:
Const SW_MAXIMIZE = 3 Extern.Declare micLong, "ShowWindow", "user32.dll", "ShowWindow", micHwnd, micLong HWND = Window("").GetROProperty("hwnd") Extern.ShowWindow HWND, SW_MAXIMIZEHi Anshoo,
What is the typical entry and exit criteria for automation testing in a project?
Vk,
It depends. Entry and Exit criteria are generally defined based upon the scope of the project and the way you have created automation.
For example, consider a function that logs in a User based upon given UserName and Password strings. An Entry criteria for this function would be if the function has found the correct page. If the correct page has been found, it can proceed to log in the user. Exit criteria would be if the page the function is on is incorrect – this will automatically throw an exception and end the function.
Excellent information about Description Object and Child Objects..
Thanks Very much Anshoo…
Cheers,
Rajendra
Hi Anshoo,
Please help me with the following:
I am using QTP10.0, Windows 7 and IE8
Problem is: QTP does not recognize webedits if DP is used. It gives error “Cannot identify the object “[ WebEdit ]” (of class WebEdit). Verify that this object’s properties match an object currently displayed in your application.”
Code is below”
systemutil.run “iexplore.run”, “http://www.mortgagecalculator.org/”
Set browdesc = description.Create()
browdesc(“title”).value = “.*”
Set pdesc = description.Create()
pdesc(“title”).value = “.*”
Set editdesc=description.Create() ‘For Home Value Edit box
editdesc(“micclass”).value=”WebEdit”
editdesc(“html tag”).value=”INPUT”
editdesc(“name”).value=”param[homevalue]”
editdesc(“type”).value=”text”
if browser(browdesc).page(pdesc).webedit(editdesc).exist(1) then
print “Home value exists”
else
print “Home value does not exists”
end if
Is the combination of OS and QTP version creating problem?
Kindly help.
Regards,
Radhika
Radhika,
Use the following description and see if it works:
Set editdesc=description.Create() editdesc("name").value="param\[homevalue\]"Anshoo,
Please clarify my queries in qtp.
I want to do automate test on web application.I have recorded it and executed.It works fine while executing but after finishing the execution i want to exit from the application and qtp should get stop. For that i have used Browser(“EaZy REcruitment”).close and Browser(“EaZy REcruitment”).stop but while using those property system close the browser and restart the steps again that mean open a new browser.
How can i stop qtp after finishing execution?
One more query: Please provide the script for check box.
While executing i got below mentioned error, pls clarify that too ASAP.
The “[ WebCheckBox ]” 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.
For #1, I think this may be because QTP is running off a DataTable and completing all iterations as it should. You may have to tweak the way your test iterates around the DataTable.
For #2, you see the following error:
because the supplied description for the WebCheckBox matches more than a single WebCheckBox. A description must be unique, so try adding properties that uniquely identify the WebCheckBox with or without the use of Ordinal Identifiers.
Please tell how to capture tab function using qtp? Qtp is not captured tab functionality while clicking on the tab menu.
Please provide it.
Thanks in advance
Hi,
I am a just started to learn QTP, pls send me some QTP sample exercises Scripts.
My mail id is baburaya@gmail.com.
Thanks
Babu
Hi Anshu,
Thanks a lot…Some how i get exactly the same thing that i am looking for from this blog.
The blog was very well explained and to top it all reading the comments section cleared all my doubts.
Thanks once again !!!!!
Thank you Gaurav!!
Hi Anshu,
A small question
In my applicatin this line works fine
browser(bDesc).page(pDesc).Link(vdesc).highlight
but using this i can only highlight the functions.Is thr any posibility that i can pass (link,webelement,webbutton) as a parameter and create a single function to verify all of them.
Something like this
vals = “Link”
browser(bDesc).page(pDesc).vals(vdesc).highlight
Vals= “Webelement”
browser(bDesc).page(pDesc).vals(vdesc).highlight
Do reply if its possible.
Thanks
Hi
Can anyone help me with this
Thanks
Gaurav,
Its not possible. We can’t pass the class of the object in the way you’ve described. One way is:
Function isObjectFound(oChild) 'As Boolean isObjectFound = False If oChild.Exist(0) Then isObjectFound = True End Functionand another, modifying your code and using Execute statement:
Execute "Browser(""" & bDesc & """).Page(""" & pDesc & """)." & vals & "(""" & vDesc & """).Highlight"Could you give some examples of iterating through tables using object descriptions ?
Hi Anshoo,
I am using ‘on error resume next’ in my script.
And I need that whenever QTP encounters an error, it should get logged.
We do have msgbox err.description statements in between the script but it only lists the last error that was encountered. How to log an error as soon as it is encountered?
Unfortunately, the only way to log it whenever it is encountered is by adding Err.Description after each line.. You may also want to see the following article: http://relevantcodes.com/gui-objects-vbscript-try-catch-finally/.
Hi Anshoo,
I am working with “expedia.com” and trying to use DP.
There is a webelement at the bottom of the page “Search for Flight+Hotel” and the code is as below.
Set myp = browser(“title:=.*”).page(“title:=.*”)
Set mywe = description.Create()
mywe(“micClass”).value = “WebElement”
mywe(“html tag”).value = “DIV”
mywe(“innertext”).value = “SEARCH FOR FLIGHT + HOTEL”
myp.webelement(mywe).click
Error i am getting is:
“Cannot identify the object “[ WebElement ]” (of class WebElement). Verify that this object’s properties match an object currently displayed in your application.”
Kindly help.
Thanks
Radhika
Radhika, try this:
Browser("title:=Expedia.*").WebElement("innertext:=SEARCH FOR FLIGHT \+ HOTEL", "class:=wizBtn2MB").ClickHi Anshoo,
I am trying to verify “Gmail” logo on every page right from login-in to account and want to verify it on every page using DP.
But when i refer to “Gmail” logo property values, i see they keep on changing. Only the ‘src’ property remains same and ‘href’, ‘url’ are changing on every page.
Do i need to create description class for every page to verify logo?
set mylogo = description.create()
mylogo(“src”).value = “https://mail.google.com/mail/help/images/logo1.gif”
mylogo(“href”).value = (keeps changing)
mylogo(“url”).value = (keeps changing)
Kindly help.
Thanks,
Radhika
Radhika, try using either class or html id:
Print "class: " & Browser("title:=Gmail.*").WebElement("class:=a9 Rgky9").Exist(0) Print "id: " & Browser("title:=Gmail.*").WebElement("html id:=:rm").Exist(0)Hi Anshoo,
I have an excel with 2 working sheets in it named “Testdata1″, “Testdata2″. My Script runs successfully and inserts data into these worksheets.
My problem is how do i make “Testdata2″ visible and can see data being inserted there when my script is running. I can only see “Testdata1″ sheet when my script starts and till it ends.
Kindly help.
Radhika
Hey…
Your article was very useful and thanks a lot for this information !!
Anila
great article!
I started dynamic dp from this week, so this will be a good starting point…thanks.
Mark
Great write up.
Do you by chance know why objDesc.value input is limited to the 255 chars limit of variable names? For example: If I wanted to locate an object by it’s innertext and that innertext was 300 chars.
I am using regex but it is still failing on anything over 255 chars. If I limit the input to 250 chars and append leading and trailing ‘*’s it will work. But I need to use all 300 chars to ensure that the object is displaying proper data.
Dennis: I’ve never encountered a situation where I had to use a long string for recognition. I generally use Regex to condense and only use the important, most relevant parts of the string if its a long string. But you’re right, I haven’t been able to have a long string (391 characters) recognized by QTP.
Hey Anshoo,
could you please help me in understanding the following regexp ?
oDesc(“innertext”).Value = “\d+”
Thanks,
Jena
Jena,
\d+is a RegExp meta character that matches any available digit one or more number of times in a given string.Hi Anshoo,
Can we print all the properties and its values using script which we see using object spy for any object?
I tried with GetTOProperties, but it is only giving me 3 property:value pair.
set obj = Browser(“Google”).Page(“Google”).link(“Advanced search”).GetTOProperties
For i=0 to obj.count
values = obj(i).name & “;” & obj(i).value & vbnewline
print values
Next
I also tried using GetROProperty, but could not.
Can you please help me to get all the property:value pair which we see using Object Spy?
Thanks,
Radhika
Radhika,
Do you want the list of TO properties or RO? For RunTime properties, you can view the custom GetROProperties.
Hi Anshoo,
I was trying description.create concept to select the menu File>Exit in flight reservation application windows. Below is what I had tried, but did not work. I even am not sure if we can use this concept to select a menu. Kindly help.
Dim oMenu
DIm colObject
Set oMenu = Description.Create
oMenu(“micclass”).value = “WinMenu”
Set colObject = Windows(“”).WinMenu(“”).ChildObjects(oMenu)
colObject.Select “File;Exit”
Anshoo,
I have a VB combo box which I can highlight but can not select a value as QTP gives the error about object not visible.
I tried “Type MicReturn” but it is not helping, As nothing can be typed in Combo Box.
Any idea you have about how to resolve.
Thanks.
can anyone send me the complete vbscripts , which are used for qtp… or watever vbscripts you all have send to my mail id…
Thanks & Regards,
Karthikeyan.A.S
can anyone send me the complete vbscripts , which are used for qtp… or watever vbscripts you all have send to my mail id karthi1401@gmail.com
Thanks & Regards,
Karthikeyan.A.S
Hi Anshoo
First of all thanks for this great document.
I have a problem in getting RO Property of a WebElement. I wanted to get outertext value of a Webelement having html tag and height as unique properties in the page. So I have scripted in following way. But it does not work
msgbox Browser (“title:=x”).Page(“title:=x”).WebElement(“html tag:=B”,”height:=16″).GetROProperty(“outertext”)
But when I have scripted as mentioned below. It is working fine. Note that colObject.count is 1 in the page
Dim oDesc
set oDesc=Description.Create
oDesc (“micclass”).value =”WebElement”
oDesc(“html tag”).value = “B”
oDesc (“height”).value =16
Set colObject =Browser (“title:=x”).Page(“title:=x”).ChildObjects (oDesc)
For i=0 to colObject.count -1
msgbox colObject(i).GetROProperty(“outertext”)
Next
Can you please tell me how can I script this in a single line
Nithya: you can do so by using the index property. Example:
MsgBox Browser ("title:=x").Page("title:=x").WebElement("html tag:=B","height:=16", "index:=1").GetROProperty("outertext")PS. I would not recommend using the height property. It is VERY likely that this can change and break your test.
Hi Anshoo,
I’m very new to QTP, but have some experience with web applications testing. So I have one question regarding object identifications in QTP and probably DP. Is it possible to use xpath for determing object in QTP? And if no, could you help me with resolving such issue? I have the application with such part of code inside:
Some error text…
……
Some error text…
……
I need to check the text in tags, so I should identify that object. But I have a lot of the same objects on one page.
Do you have any ideas how can I do that?
Thanks in advance,
Julia.
Sorry, forgot to include code example in special tags ;)
< dd id="password-element".... <input ..... <ul..... <li Some error text < dd id="passwordRepeat-element".... <input ..... <ul..... <li Some error textI need to check text in “li”
Hi Anshoo,
On what basis (Parameter / Factor) risk of a particular complex scenario that has to be automated will be calculated?
Thanks in Advance,
Sanjeev.
Hi Anshoo,
I faced the below question in an interview
“How many scripts are there in your application? On what basis will you classify the minor / major change?”
Thanks in Advance,
Sanjeev
i need 2 access all the objects at ones from repository with its properties . i need the code. plz help me. n the properties should be converted in html file.
i want to access all the object properties from the object repository at ones. i need the code. can u help me?
Very good article.
Very useful.
Hi,
Could you please provide me the code for how to open ” C drive ” through QTP script ,Then how to navigate files accosiated to that drive. Please provide me the code as soon as possible . It will be very helpful for me.
My Mail ID: Shriniwasreddy@yahoo.com
Thanks in advance…..
Regards,
Shri
Hi,
Can you help me in QTP by providing some practical exercises & Docs. I am a beginner. My mailid is vajja.bharath@gmail.com.
Thanks,
Bharath
Great work Anshoo! Your posts on this site and many other forums helped me resolve so many issues. very grateful to you.
hoping this one gets answered too -
I have a webtable with same link ( Edit) in each row (there are many other links in this row). I know the row & column in which the link appears but the index of the link keeps changing. Can you tell me how to write a function/code snippet to click the link in the webtable.
Supraja, It would be something like this:
Browser("Some Title").WebTable("Description of Table").ChildItem(Row, Column, "Link", 0).ClickHi Anshoo,
I am unable to click on the object which has been identified using description object reference.
I have written the below code:
Set vResult = Description.Create()
vResult(“html tag”).value = “A”
vResult(“href”).value = “.*job-listings.*”
vResult(“micClass”).value = “Link”
Set allItems = Browser(“title:=.*”).Page(“title:=.*”).ChildObjects(vResult)
For i = 1 to allItems.count
allItems(i).Highlight ‘Working fine
allItems(i) ‘Not able to click
Next
Please advise
Pushkar, you forgot to add the .Click event it seems after allItems(i).
Hey!
Thanks for the quick response!
You are right, but I was thinking that maybe regular expressions could help (^) to retrieve objects with a property different than a specific value.
Regards,
ReGex is possible, but only for some properties. This is a limitation that has become more prominent as people have sought advanced use of the description object. I hope HP will someday address this..
Hi Anshoo,
thanx for the reply.
But i tried this also, still its giving me all the child objects instead of FlexList objects.
Hi Anshoo,
Thanks for the reply, but I think, using this I can only get the value of one object only.
But if I want to create and use the description of multiple objects with more properties, how can I do that.
Please elaborate
Thanks
I mean, I just want to create a function which only contains the description of all the objects, which I want to use my complete test project like an Object Repository.
You’re correct. The above approach will allow you to create a single Description Object, and this is also the technique I would recommend. It’s always easier and more descriptive when you’re assigning a new object reference through a function call, and easier understood by another member of your team.
Example:
Dim DescriptionDict Set DescriptionDict = CreateObject("Scripting.Dictionary") With DescriptionDict .Add "SearchTextBox", "html tag:=Input||name:=q" .Add "SearchButton", "value:=Google Search" End With 'Your code to form the descriptions Set DescriptionDict = NothingComplete solution:
Set dicDescription = CreateObject("Scripting.Dictionary") With dicDescription .Add "SearchTextBox", "html tag:=Input||name:=q" .Add "SearchButton", "value:=Google Search" End With Keys = dicDescription.Keys Items = dicDescription.Items For ix = 0 to dicDescription.Count - 1 Execute "Set " & Keys(ix) & " = Description.Create" arrArray = Split(Items(ix), "||") For Each Desc in arrArray Execute Keys(ix) & "(" & Chr(34) & Split(Desc, ":=")(0) & Chr(34) & ").Value = " & Chr(34) & Split(Desc, ":=")(1) & Chr(34) Next Next 'Description Object: SearchTextBox Print SearchTextBox("html tag") 'Description Object: SearchButton Print SearchButton("value") Set dicDescription = NothingWhat is
m_target?Please see this article as well which is written by the same folks who develop Flex. You may find some techniques in that helpful. I haven’t had a chance to work with Flex, and tried to inquire about this issue from colleagues but I feel that that there is a very very small user-group that is currently automation Flex apps. I know this doesn’t solve your problem, but can you try to post this issue on HP’s forums? Maybe someone there might be able to help. I searched OpenView as well, but there are no documents pertaining to this issue.
If nothing seems to work, you can post in this thread and seek Roi’s help.. He works for HP and may be able to provide a better understanding of this scenario..
No, there is no add-in
Is that required…?
I got it,,,
Thank you
It will be required depending upon the technology of your application. Without the correct add-in, you won’t be able to successfully automate it..
Hi, Anshoo,
Oh! I got it! Thank you very much. I think I’ve understood the reason.
It seems I also can do as follow:
objDesc ("innertext").RegularExpression = falseThanks again. :)
Regards,
Dennis
Yes! You can also disable ReGex for the object description. Glad its working now.
Thanks Anshoo.
As you said , the first issue has been completed. Can you give example [script] for selecting more than one value in check box which are in web application?
Hi Anshoo,
About #2, I have to do the same thing as Pavi, I need to retrieve the immediate parent object of a WebElement, I have tried this line but it returns the Page or the Browser as the parent instead of the immediate parent that would be another WebElement and in some cases a WebTable.
Set oParent = obj.GetTOProperty(“parent”)
Have you done this before? I’d appreciate your help.
Regards,
Israel
A WebCheckBox can only take the following 2 values: On and Off. If we pass 2 or more values, that would simply toggle the CheckBox on and off..
Israel,
GetTOProperty(“parent”) may not always give you the “correct” immediate parent. For that, you will have to use HTML DOM methods. Please see the below function for example, which retrieves the parentNode depending upon the levels provided:
Usage:
Print getParentNode(Browser("title:=Google").WebEdit("name:=q"), 1) Print getParentNode(Browser("title:=Google").WebEdit("name:=q"), 2) Print getParentNode(Browser("title:=Google").WebEdit("name:=q"), 3) Print getParentNode(Browser("title:=Google").WebEdit("name:=q"), 4) Print getParentNode(Browser("title:=Google").WebEdit("name:=q"), 5)Immediate parentNode: xLevelsUp = 1
Parent of immediate parent: xLevelsUp = 2
Parent of parent of immediate parent: xLevelsUp = 3
PS. Code to get the “actual” Test Object:
Public Function getParent(ByVal childObject, ByVal xLevelsUp) Set getParent = Nothing If Not childObject.Exist(0) Then Reporter.ReportEvent micFail, "getParent", "childObject not found." Exit Function End If Dim oParent, ix, iSourceIndex, sTagName, sMicClass Set oParent = childObject.GetTOProperty("parent") Set childObject = childObject.Object On Error Resume Next For ix = 1 to xLevelsUp Set childObject = childObject.parentNode iSourceIndex = childObject.sourceIndex sTagName = childObject.tagName If sTagName = "HTML" Then Exit For Next On Error Goto 0 sMicClass = oParent.WebElement("source_index:=" & iSourceIndex).GetROProperty("micclass") On Error Resume Next Execute "Set oParent = oParent." & sMicClass & "(""source_Index:=" & iSourceIndex & """)" If Err.Number = 0 Then Set getParent = oParent End If On Error Goto 0 End FunctionUsage and examples for google.com:
Set parentObject = getParent(Browser("title:=Google").WebEdit("name:=q"), 4) parentObject.Highlight Print parentObject.GetROProperty("micclass") Set parentObject = getParent(Browser("title:=Google").WebEdit("name:=q"), 5) parentObject.Highlight Print parentObject.GetROProperty("micclass") Set parentObject = getParent(Browser("title:=Google").WebEdit("name:=q"), 6) parentObject.Highlight Print parentObject.GetROProperty("micclass") Set parentObject = getParent(Browser("title:=Google").WebEdit("name:=q"), 7) parentObject.Highlight Print parentObject.GetROProperty("micclass") Set parentObject = getParent(Browser("title:=Google").WebEdit("name:=q"), 8) parentObject.Highlight Print parentObject.GetROProperty("micclass")Thanks Anshu It solved one of my problems :)
Hey Anshoo,
It worked :)
But why we have not used here “Page()” and also is it necessary to use regular expression whenever we have any kind of special characters in property values. Like what you have used here for “innertext” a “\” sign infront of “+”.
Thanks,
Radhika
Radhika,
With Web apps, its not required to use the Page object (or the Browser object for that matter). Both statements below are valid:
Browser("").WebEdit("").Set "test" Page("").WebEdit("").Set "test"For your second question, yes, if you’re using inline statements then you have to use a backslash “\” character. With the description object, you can simply evaluate RegularExpression = False.
Hi Anshoo,
From where do we get the “html id” and “class” value? Cos when i use object spy i see blank for these properties.
Kindly help.
Radhika
Radhika, not all web objects will have an ‘html id’ or a ‘class’ property assigned to it. If you require these properties to be attached to the object, you will have to contact your developers – which is unfortunately the only way.
Julia: Can you please send me the source in a text file to anshoo [dot] arora [at] relevantcodes [dot] com?
{ 1 trackback }