QTP: Understanding the Description Object (Description.Create)

by Anshoo Arora ON September 6, 2009 · Posted In All, QTP, QTP/DP · 144 comments

Learning Zone
Creative Commons License photo credit: SideLong

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.

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.

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.Count

The 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.

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

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.Count

Let’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.Count

If 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.

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.

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:

Object Spy Snapshot: Images Link (Google)

Object Spy Snapshot: Images Link (Google)

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:

(Mis)Using Integers as Strings

(Mis)Using Integers as Strings

So, always remember to treat integers as they are. This always holds true for x, y, abs_x, abs_y.

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:

Using Description.Create to Set Value

Using Description.Create to Set Value

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 :)

Subscribe to Relevant Codes (by Anshoo Arora)

Hello! We're always posting interesting articles on Relevant Codes. Why not subscribe so you don't miss out?

Leave a Comment

{ 143 comments… read them below or add one }

Aravind April 2, 2012 at 7:52 am

Hi Anshoo,

I am a beginner with QTP . Just started automating my Application. Here i have a problem.

In my script i am handling an error message through below line of statement.
If Browser(“”)page(“”).WebElement(“”).exist then

do the required steps
else

go for positive case

Here my problem is, for positive case also QT P is searching for that Web Element whether it is existed in the page or not. Because of this The performance was decreased badly

I need to execute this as part of parametrization which has to run for 20,000 records.
How i can make the execution fast..

Please give me your suggestions.

Thanks

Reply

Anshoo Arora April 3, 2012 at 2:28 am

Aravind, you can use .Exist(0) instead of .Exist(). This should resolve the performance issue.

Reply

Aravind April 3, 2012 at 4:33 am

I used Exist(0). I Have the same problem.
Please suggest me some other solution.

Thanks

Reply

Eshwar April 25, 2012 at 2:40 am

take Exist(20) for positive results….

Reply

Mohan April 2, 2012 at 7:00 am

Hi,

How to handle multiple Web Edit boxes in a page using single Description Object.
Here my main point is With Single Web Edit Object ,how can i access multiple WebEdit boxes

Reply

Anshoo Arora April 3, 2012 at 2:28 am

Mohan, a quick example to work with all WebEdits:

Dim desc, childObjects, ix

Set desc = Description.Create
desc("micclass").Value = "WebEdit"

Set childObjects = Browser("").Page("").ChildObjects(desc)

For ix = 0 To childObjects.Count - 1
    childObjects(ix).Set "value"
Next

Reply

Mohan April 3, 2012 at 6:53 am

Thanku Anshoo,

I Need to create a Global Function for all Web Edits in my Application.

Here i don’t want to create object for Web Edit Every time.I can create a Global function and i call that function where-ever i Need.

Example:-
Function WebEdit_Handle()
Set WebEdit_All = Description.create()
WebEdit_All(“micclass”).value = “WebEdit”
return set WebEdit_Handle = WebEdit_All
EndFunction

WebEdit=WebEdit_Handle();

Set childObjects = Browser(“”).Page(“”).ChildObjects(WebEdit)

For ix = 0 To childObjects.Count – 1
childObjects(ix).Set “value”
Next

Is this way i can Handle Web Elements Globally? Correct..

Reply

Anshoo Arora April 4, 2012 at 2:25 pm

Mohan, that is surely one way to handle description objects for reuse..

Reply

Piyush March 28, 2012 at 12:11 am

Hi Anshoo,
How can I enter/set different values in all webedits on a page using childobjects,the same value can be set as below
Set objDesc = Description.Create
objDesc(“micclass”).Value = “WebEdit”

Set Child = Browser(“Google”).Page(“Yahoo! Mail: The best”).ChildObjects(objDesc)

For iCount = 0 to Child.count -1
Child(iCount).Highlight
Child(iCount).Set “Divya Rakesh”
Next

But how I set different values in different webedits?

Please suggest.

Reply

Anshoo Arora March 28, 2012 at 9:40 am

Piyush, you will have to use a variable for the Set event. The variable can receive value from an array, dictionary, DataTable or any external source like Text, XLS, XML etc.

Reply

GEIKD March 15, 2012 at 11:42 pm

THIS IS NOT AN OBJECT!FOOLISH!!!!

Reply

Yaron March 12, 2012 at 2:52 am

Hi,

I run the following command in function that receive object, desc as parameters:
set childs = object.childObjects(desc)

In some case I receive that childs.count =1 but in childs(0) I got empty variable

What can cause this problem

Reply

Anshoo Arora March 15, 2012 at 9:22 am

Yaron, what do you get when you run the following code:

MsgBox childs(0).GetROProperty("micclass")

It shouldn’t be empty.. each element in the collection should contain a Test Object.

Reply

Sunder Natarajan March 2, 2012 at 6:33 pm

Excellent Article. I’m in the process of automating a web based application, and feel this forum is an excellent sournce of information.

My question is as follows:
The webpage I’m working on has many sections (Say A,B,C). There is an image which needs to be clicked which then opens the corresponding forum. Say user clicks on image A completed the forum, then clicks on Image B which opens up the B form.

Now, the Parent details (Browser and Page) depend on which section of the page I”m in. That is if I click A when I’m in B form, the Browser and Page title is B, if I click on A from C form, the Parent Browser and Page is C.

However the only consisten property is the file Name and Class. I defined an object as follows:
Set SectionA=Description.Create
SectionA(“micclass”).value=”image”
SectionA(“File Name”).value=”fileA”

Now can I use a click method on this object? Can you please guide me on this. Note, I cannot user the parents of this object (Browser and Page) as they are dynamic and change depending upon which section I’m in.

Thanks,
Sunder

Reply

Anshoo Arora March 15, 2012 at 8:56 am

Sunder, one of the obvious ways to work in this scenario is keeping tracking (storing) the titles of the browsers. Another way is, as soon as they open, store their hwnd. Example:

'Click Image1 -> Browser1 opens
hWnd_1 = Browser("index:=0").GetROProperty("hwnd")

'Click Image2 -> Browser2 opens
hWnd_2 = Browser("index:=0").GetROProperty("hwnd")

'Test:
Browser("hwnd:=" & hWnd_1).Highlight
Browser("hwnd:=" & hWnd_2).Highlight

Reply

Ramdas February 23, 2012 at 1:21 am

How to identify the webeditbox which is next to that webelement???
Thanks

Reply

Anshoo Arora March 15, 2012 at 8:24 am

Ramdas, you can use visual relational identifiers if you’re using QTP 11. If not, it can vary depending upon the html structure, if the items are in a table, if one can be used as an anchor to get to the other using DOM etc.

Reply

RP February 22, 2012 at 3:38 pm

Hi Anshoo,

Nice article. Can this concept be applied to actual objects on the Desktop? I am trying to open a particular application thru the Desktop but am unable to identify any object (individually) on the Desktop. On using below code, i was able to get the count of objects on the desktop, but still not able to identify any of them:

intCount = Window(objWindow).WinListView(objWinListView).GetItemsCount

Could you help in identifying and opening an object on the desktop?

Thanks,
RP

Reply

Anshoo Arora March 15, 2012 at 8:22 am

RP, try this:

Set oDesc = Description.Create
Set oBase = Desktop.ChildObjects(oDesc)

For ix = 0 to oBase.Count - 1
    Print oBase(ix).GetROProperty("regexpwndtitle")
Next

Reply

Imran Khan February 14, 2012 at 4:33 am

hi Anshoo,

i have a link which keeps on changing on every iteration something like ” 74843284 – 84384932:Activated “or” 74843284 – 84384932:Suspended “or” 74843284 – 84384932:Disconnected “. The full text can also keep on changing except the hyphen and the colon. I was using winrunner where i had the option to use the command web_obj_get_text, this will get me the text of the link and then i can set it up as temporary buffer in the GUI file. however with QTP it doesnt seem that easy. i have click on the link and also get the status of the link in my testing. Can you please help with this?

Reply

Imran Khan February 14, 2012 at 4:43 am

I have tried something as below

BAN = DataTable(“BAN”, dtGlobalSheet) ‘ Declaring variable for BAN
‘print BAN
MSISDN = DataTable(“MSISDN”, dtGlobalSheet) ‘ Declaring variable for MSISDN
‘print MSISDN
Installed_Link = MSISDN & ” – ” & BAN & “:Activated” ‘ Declaring the Installed services link. But i need to get Activated first.
print Installed_Link

‘Account_Link = BAN & “:”
‘print Account_Link

Dim oDesc ‘Description Object
Dim colObject ‘Object Collection

Set oDesc = Description.Create
oDesc( “micclass” ).value = “Link”
oDesc( “text” ).value = Installed_Link

Set colObject = Browser( “Browser”).Page(“360-Degree View”).ChildObjects( oDesc )

MsgBox colObject.Count

this one gives me the count, however i need to get the text of activated first and then click on it was well, which is not happening

Reply

Anshoo Arora February 16, 2012 at 10:47 am

Imran, you can use a wildcard and use only the static part to identify the link:

Browser().Page().Link("innertext:=.*Activated", "index:=0").Click
Browser().Page().Link("innertext:=.*Suspended", "index:=0").Click
Browser().Page().Link("innertext:=.*Disconnected", "index:=0").Click

Reply

Shalabh Dixit February 10, 2012 at 2:25 am

Can anybody please provide their valuable inputs on difference between “Description.Create” and “CreateObject”.

Thanks
Shalabh Dixit

Reply

Anshoo Arora February 13, 2012 at 12:21 pm

Shalabh, Description.Create is a QTP specific object that is used to create a Description object of property-value pairs. For example:

(Property) innertext = (value) Images
(Property) html tag = (value) A

CreateObject is a VBScript way of binding to a COM object like Scripting.Dictionary, Scripting.FileSystemObject, Mercury.Clipboard etc and using their methods from it.

Reply

Pushkar January 7, 2012 at 12:33 pm

Hi 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

Reply

Anshoo Arora January 12, 2012 at 11:50 am

Pushkar, you forgot to add the .Click event it seems after allItems(i).

Reply

supraja January 3, 2012 at 3:17 pm

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.

Reply

Anshoo Arora January 12, 2012 at 11:41 am

Supraja, It would be something like this:

Browser("Some Title").WebTable("Description of Table").ChildItem(Row, Column, "Link", 0).Click

Reply

bharath December 22, 2011 at 8:05 am

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

Reply

shri November 17, 2011 at 7:27 am

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

Reply

anushachanda October 31, 2011 at 1:50 am

Very good article.
Very useful.

Reply

nimesh October 16, 2011 at 7:54 am

i want to access all the object properties from the object repository at ones. i need the code. can u help me?

Reply

nimesh October 16, 2011 at 7:52 am

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.

Reply

sanjeev October 10, 2011 at 4:29 am

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

Reply

sanjeev October 10, 2011 at 4:27 am

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.

Reply

Julia October 5, 2011 at 2:15 pm

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.

Reply

Julia October 5, 2011 at 2:26 pm

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 text

I need to check text in “li”

Reply

Nithya September 15, 2011 at 9:55 am

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

Reply

Anshoo Arora September 24, 2011 at 8:31 pm

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.

Reply

karthikeyan August 1, 2011 at 5:44 am

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

Reply

karthikeyan August 1, 2011 at 5:42 am

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

Reply

Mini April 5, 2011 at 12:58 am

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.

Reply

Sonal February 27, 2011 at 6:21 am

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”

Reply

Radhika February 23, 2011 at 1:14 pm

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

Reply

Anshoo Arora February 28, 2011 at 7:29 am

Radhika,

Do you want the list of TO properties or RO? For RunTime properties, you can view the custom GetROProperties.

Reply

Jena February 22, 2011 at 4:51 am

Hey Anshoo,
could you please help me in understanding the following regexp ?

oDesc(“innertext”).Value = “\d+”

Thanks,
Jena

Reply

Anshoo Arora February 23, 2011 at 2:18 am

Jena,

\d+ is a RegExp meta character that matches any available digit one or more number of times in a given string.

Reply

Dennis M February 10, 2011 at 5:22 pm

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.

Reply

Anshoo Arora February 19, 2011 at 7:18 am

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.

Reply

markQA January 29, 2011 at 7:41 pm

great article!

I started dynamic dp from this week, so this will be a good starting point…thanks.

Mark

Reply

Anila January 25, 2011 at 5:51 am

Hey…
Your article was very useful and thanks a lot for this information !!
Anila

Reply

Radhika January 14, 2011 at 12:48 pm

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

Reply

Radhika January 13, 2011 at 3:45 pm

Hi 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

Reply

Anshoo Arora January 22, 2011 at 7:15 am

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)

Reply

Radhika January 10, 2011 at 2:57 pm

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

Reply

Anshoo Arora January 10, 2011 at 3:04 pm

Radhika, try this:

Browser("title:=Expedia.*").WebElement("innertext:=SEARCH FOR FLIGHT \+ HOTEL", "class:=wizBtn2MB").Click

Reply

vk October 17, 2010 at 12:39 pm

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?

Reply

Anshoo Arora November 14, 2010 at 5:16 pm

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/.

Reply

Sanjay October 15, 2010 at 3:46 pm

Could you give some examples of iterating through tables using object descriptions ?

Reply

Gaurav Anand October 14, 2010 at 7:41 am

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

Reply

Gaurav Anand October 18, 2010 at 8:36 am

Hi

Can anyone help me with this

Thanks

Reply

Anshoo Arora November 14, 2010 at 5:14 pm

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 Function

and another, modifying your code and using Execute statement:

Execute "Browser(""" & bDesc & """).Page(""" & pDesc & """)." & vals & "(""" & vDesc & """).Highlight"

Reply

Gaurav Anand October 14, 2010 at 3:52 am

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 !!!!!

Reply

Anshoo Arora November 14, 2010 at 5:08 pm

Thank you Gaurav!!

Reply

Babu October 12, 2010 at 9:07 am

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

Reply

svanmitha October 4, 2010 at 12:19 am

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

Reply

svanmitha September 22, 2010 at 7:40 am

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.

Reply

Anshoo Arora September 29, 2010 at 3:10 pm

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:

The “[ WebCheckBox ]” object’s description matches more than one of the objects currently displayed in your application.

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.

Reply

Radhika September 21, 2010 at 1:41 pm

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

Reply

Anshoo Arora September 29, 2010 at 3:07 pm

Radhika,

Use the following description and see if it works:

Set editdesc=description.Create()
editdesc("name").value="param\[homevalue\]"

Reply

Rajendra September 13, 2010 at 5:08 am

Excellent information about Description Object and Child Objects..
Thanks Very much Anshoo…

Cheers,
Rajendra

Reply

vk August 28, 2010 at 11:52 am

Hi Anshoo,

What is the typical entry and exit criteria for automation testing in a project?

Reply

Anshoo Arora September 2, 2010 at 7:37 am

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.

Reply

Ranjana August 10, 2010 at 1:35 am

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.

Reply

Anshoo Arora August 11, 2010 at 3:20 pm

Ranjana,

Try this:

Const SW_MAXIMIZE = 3

Extern.Declare micLong, "ShowWindow", "user32.dll", "ShowWindow", micHwnd, micLong
HWND = Window("").GetROProperty("hwnd")

Extern.ShowWindow HWND, SW_MAXIMIZE

Reply

Dennis July 6, 2010 at 3:43 am

It 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]

Reply

Dennis July 6, 2010 at 3:29 am

Hi, Anshoo,

I cannot use ChildObjects for finding a WebElement. Following is the example

For example, we have a html:


WebTest

DP is cool!

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.count

The result always be zero. That means QTP cannot find it. Why?

Maybe I can use the .Object.getElementsByTagName to 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

Reply

Anshoo Arora July 6, 2010 at 9:27 pm

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 1

Reply

Pavi April 14, 2010 at 4:19 am

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

Reply

Anshoo Arora April 14, 2010 at 3:25 pm

#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?

Reply

Neelakantan G S April 14, 2010 at 12:41 am

Its very nice article for the beginners…

Reply

Anshoo Arora April 14, 2010 at 3:23 pm

Thank you Neelakanthan, I’m glad it helped :)

Reply

San March 30, 2010 at 1:09 am

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

Reply

Anshoo Arora April 1, 2010 at 8:17 pm

What add-in is it, San? .NET?

Reply

Devender Kumar March 29, 2010 at 8:34 am

Hi San,

May be Environment variable helps you out to store the collection and retreive in-between the tests.

Reply

Devender Kumar March 29, 2010 at 8:32 am

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.Count

but 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????

Reply

Anshoo Arora March 29, 2010 at 12:57 pm

Devender, try this:

Set EditDesc = Description.Create
EditDesc("micclass").Value = "FlexList"

Set m_Child = m_Target.ChildObjects(EditDesc)
MsgBox m_Child.Count

Reply

San March 29, 2010 at 2:32 am

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

Reply

Anshoo Arora March 29, 2010 at 12:56 pm

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 Function

If 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).Count

The above function can certainly be extended for more properties and values. I hope this helps :)

Reply

shivani March 8, 2010 at 2:25 am

thanks

Reply

Israel February 24, 2010 at 8:27 pm

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!

Reply

Anshoo Arora February 24, 2010 at 10:30 pm

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
Next

Reply

Steve Langille February 19, 2010 at 9:15 am

Thanks much Anshoo!

Steve

Reply

Anshoo Arora February 19, 2010 at 9:35 am

:)

Reply

Steve Langille February 18, 2010 at 12:40 pm

How 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

Reply

Anshoo Arora February 19, 2010 at 1:42 am

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+"

Reply

Babu February 6, 2010 at 5:03 am

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

Reply

Anshoo Arora February 10, 2010 at 2:13 pm

Hi Babu,

If you’re using DP:

For ix = 1 to 4
    Browser("Login").Page("Application").Frame("folderFrame").Link("innertext:=Link" & ix).Click
Next

If you’re using OR:

For ix = 1 to 4
    Browser("Login").Page("Application").Frame("folderFrame").Link("Link" & ix).Click
Next

Reply

sam January 26, 2010 at 1:09 am

excellent info, If you have more things to I would very much aprreciate it.

Reply

Anshoo Arora January 26, 2010 at 11:06 am

Thanks, Sam. I will try to post a few more such articles in the coming weeks!

Reply

Jason January 6, 2010 at 12:06 pm

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:

div id="unique_id_1"
   input type="text" class="non_unique_class"
/div

div id="unique_id_2"
   input type="text" class="non_unique_class"
/div

Reply

Anshoo Arora January 7, 2010 at 5:27 am

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 With

or:

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 With

Reply

Jason January 6, 2010 at 12:02 pm

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

Reply

Anshoo Arora January 7, 2010 at 5:36 am

Jason,

You can wrap your code around:

p r e
/ p r e

(without spaces)

Reply

Suraj November 20, 2009 at 5:35 am

Good Explaination with examples ,thank you

Reply

Anshoo Arora November 20, 2009 at 11:58 am

Glad it helped! :)

Reply

alkaa October 3, 2009 at 5:01 am

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..

Reply

Anshoo Arora October 3, 2009 at 11:24 am

can we use micClass universally in descriptive programing everywhere like with browser, page, text and combo

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").Highlight

It 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.

Reply

alkaa October 1, 2009 at 4:05 am

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,

Reply

Anshoo Arora October 1, 2009 at 6:39 pm

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"
Next

I hope this helps.. If you’re still unclear, we can create a working example too.

Reply

Pragya September 25, 2009 at 2:09 pm

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?

Reply

Anshoo Arora September 26, 2009 at 6:11 pm

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 - tStart

Which one gives a better time?

I see that UBound(arr) gives a different answer in these cases.. Can you please explain me why?

Using the same array above, when I execute the following line, I get 9:

'Returns 9
MsgBox UBound(arrArray)

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?

Reply

Sangeetha September 17, 2009 at 11:54 am

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

Reply

Anshoo Arora September 17, 2009 at 7:07 pm

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.

what is this linefeed?

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.

Reply

Charles August 6, 2010 at 5:37 am

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.

Reply

Charles August 6, 2010 at 5:41 am

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.

Reply

Anshoo Arora September 16, 2009 at 5:46 pm

Thanks! :)

Reply

sunitha September 16, 2009 at 3:53 am

Hi Anshoo,

The Description object article is very clear with examples.keep up the good work

Regards
Suni

Reply

Charles August 6, 2010 at 5:34 am

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.

Reply

Israel February 24, 2010 at 11:01 pm

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,

Reply

Anshoo Arora February 28, 2010 at 5:41 pm

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..

Reply

Devender Kumar March 29, 2010 at 11:31 pm

Hi Anshoo,

thanx for the reply.
But i tried this also, still its giving me all the child objects instead of FlexList objects.

Reply

San March 30, 2010 at 12:55 am

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

Reply

San March 30, 2010 at 12:57 am

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.

Reply

Anshoo Arora April 1, 2010 at 8:15 pm

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 = Nothing

Complete 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 = Nothing

Reply

Anshoo Arora April 1, 2010 at 8:08 pm

What 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..

Reply

San April 2, 2010 at 12:28 am

No, there is no add-in
Is that required…?

Reply

San April 2, 2010 at 12:30 am

I got it,,,
Thank you

Reply

Anshoo Arora April 2, 2010 at 1:27 am

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..

Reply

Dennis July 7, 2010 at 12:49 am

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 = false

Thanks again. :)

Regards,
Dennis

Reply

Anshoo Arora July 8, 2010 at 12:29 pm

Yes! You can also disable ReGex for the object description. Glad its working now.

Reply

svanmitha October 1, 2010 at 4:19 am

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?

Reply

Israel Valencia October 25, 2010 at 7:30 pm

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

Reply

Anshoo Arora November 14, 2010 at 4:54 pm

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..

Reply

Anshoo Arora November 14, 2010 at 6:18 pm

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:

Public Function getParentNode(ByVal object, ByVal xLevelsUp)
	getParentNode = ""
	If Not object.Exist(0) Then Exit Function

	Dim ix

	Set object = object.Object

	For ix = 1 To xLevelsUp
		Set object = object.parentNode
		If object.tagName = "HTML" Then Exit For
	Next

	getParentNode = object.tagName
End Function

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

Reply

Anshoo Arora November 14, 2010 at 6:51 pm

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 Function

Usage 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")

Reply

Gaurav Anand November 16, 2010 at 9:57 am

Thanks Anshu It solved one of my problems :)

Reply

Radhika January 10, 2011 at 3:25 pm

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

Reply

Anshoo Arora January 22, 2011 at 7:05 am

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.

Reply

Radhika February 2, 2011 at 11:38 am

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

Reply

Anshoo Arora February 19, 2011 at 7:04 am

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.

Reply

Anshoo Arora October 11, 2011 at 4:45 pm

Julia: Can you please send me the source in a text file to anshoo [dot] arora [at] relevantcodes [dot] com?

Reply

Anshoo Arora February 16, 2012 at 10:48 am

Imran, to get the text of Activated, you can use this:

sText = Browser().Page().Link("innertext:=.*Activated", "index:=0").GetROProperty("innertext")
MsgBox sText

Reply

{ 1 trackback }

Previous post:

Next post: