QTP – Descriptive Programming (DP) Concepts 1

Introduction

Descriptive programming has become the technique of choice for many QTP test developers. We can talk about its advantages and disadvantages all day, but here, we’ll only discuss the concepts and come up with our own idea of what it does better, and what it doesn’t :). This is going to be a very quick refresher before we move on to its everyday application by completing an end-to-end testcase.

The idea behind descriptive programming is for automation developers to instruct QTP which properties they would like to use to identify an object, instead of having QTP to choose them itself. If done correctly, this can help create robustness in scripts, ultimately requiring less maintenance-time and more development time.

Let’s begin.

But wait, before we really begin, we must understand QTP’s Object Spy. It is an inbuilt tool that enlists all of the test-object and runtime-object properties. These properties are different for different types for objects. For example, an image has a property called ‘file name’ whereas a listbox doesn’t. Instead, a listbox has a special ‘all items’ property whereas the image doesn’t. This discussion will be limited to the usage test-object properties to identify objects. Below are 2 snapshots of the Object Spy:
p>

Object Spy Icon

Object Spy Icon

Object Spy Window

Object Spy Window

Now, let’s open www.Google.com and use the object spy to retrieve all properties of the search box:

Object Spy: WebEdit Properties

Object Spy: WebEdit Properties

Notice the image above. The editbox has a HTML TAG property with its corresponding value ‘INPUT’. This means, the editbox takes some input from the user – which is true because we do set some value in it! It also has a ‘MAX LENGTH’ property, with a value of ’2048′. This means, you can enter a maximum of 2048 characters in it (the best source to see all of the Test-Object properties of objects is the QTP help itself). Below you will see an editBox which can contain a maximum of 9 characters:

Test maxLength:

You can really use all these properties to identify this editbox, but, do we really need to use all of them? No. That is the most important idea behind descriptive programming – we only use what we need. Below is how we write descriptions for objects:

ObjectClassName("property:=value", "property:=value")
 
' ofcourse we're not limited to only 2 properties. We can write more:
ObjectClassName("property:=value", "property:=value", "property:=value")

Above, ObjectClassName (in Web applications) can be Browser, Page, Frame, WebEdit, Image etc. Properties come from the left column the ObjectSpy column whereas values are in the right column. We can include as many properties as we want, but in reality, we only need to add a few to uniquely identify the object. Knowing which properties should suffice to uniquely identify can object will come from experience and practice. Below is a description I created for this editbox (WebEdit):

'ObjectClassName( "property1:=value1", "property2:=value2" )
WebEdit( "name:=q", "html tag:=INPUT" )

I already mentioned the HTML TAG and its value INPUT above. We’ve also added a new property/value here: ‘name:=q’. Is this enough to uniquely identify the object? Yes. But is it enough to make our script work? No, sadly its not.. and that is because, we haven’t yet created descriptions for its parent objects: Browser & Page. Below are the snapshots of the spied browser and page objects:

Object Spy: Browser Properties

Object Spy: Browser Properties

Object Spy: Page Properties

Object Spy: Page Properties

Browser description
'ObjectClassName( "property1:=value1" )
Browser( "title:=Google" )
Page description
Page( "title:=Google" )

Now, we will connect all these descriptions and form a hierarchical tree:

Browser("title:=Google").Page("title:=Google").WebEdit("name:=q","html tag:=INPUT")

You might wonder why I have omitted the WebTable below the Page and above the WebEdit object. In practice, we can also skip the Page object to identify the WebEdit. But, why did I skip the WebTable after all!? When you experiment more with DP, you will discover that some objects are embedded in many WebTables, and it will become cumbersome if we were to include all WebTables in the hierarchy to get to the object of interest (thanks to the person who thought that will be a terrible idea!). Example of the previously mentioned scenario:

Object Spy: Multiple WebTables

Object Spy: Multiple WebTables

To complete the statement above, we will add an event. In QTP, events can be described as actions on target objects. For example, a WebEdit has a ‘Set’ event. we use the ‘Set’ method of a WebEdit to set a value:

Browser("title:=Google").Page("title:=Google").WebEdit("name:=q","html tag:=INPUT").Set "DP"

Set is a QTP event to put in a value in the edit box. Different objects have different events. For example: an Image has a ‘Click’ event associated with it.

This, we did without using Object Repository. The same concept applies to all objects regardless of what your environment is. We perform actions on child objects by accessing their object hierarchies. Let’s complete the above example by searching for our keywords (use the spy again on the search button):

Browser("title:=Google").Page("title:=Google").WebEdit("name:=q", "html tag:=INPUT").Set "DP"
Browser("title:=Google").Page("title:=Google").WebButton("name:=Google Search").Click

This is how the same code will look like if we had recorded this process:

Browser("Google").Page("Google").WebEdit("q").Set "DP is great"
Browser("Google").Page("Google").WebButton("Google Search").Click

These properties are now stored in QTP’s Object Repository (OR). There is another way we can create object descriptions, which is done by setting a reference:

' Creating Browser description
' "title:=Google"
Set oGoogBrowser = Description.Create
oGoogBrowser( "title" ).value = "Google"
 
' Creating Page description
' "title:=Google"
Set oGoogPage = Description.Create
oGoogPage( "title" ).Value = "Google"
 
'* Creating WebEdit description
' "html tag:=INPUt", "name:=q"
Set oGoogWebEdit = Description.Create
oGoogWebEdit( "html tag" ).Value = "INPUT"
oGoogWebEdit( "name" ).Value = "q"

Once we do the above, we can use this descriptions in our script:

Browser(oGoogBrowser).Page(oGoogPage).WebEdit(oGoogWebEdit).Set "DP is great"

The only time I use this technique is to retrive object collections through ChildObjects (we will discuss this in the coming tutorials).

Let’s do another example. Again, we will use Google, but instead of setting a value, we will click an object. You can choose any Link on the page; I chose the link ‘Images’:

Object Spy: Google Images Link

Object Spy: Google Images Link

'ClassName("property:=value").ClassName("propert1:=value").ClassName("property:=value").Event
Browser("title:=Google").Page("title:=Google").Link("innertext:=Images", "html tag:=A").Click

This time, instead of ‘Set’ we used ‘Click’. Following is a list of events we perform on Web objects:

Object Event
Image Click
WebButton Click
WebCheckBox Set
WebEdit Set
WebElement Click
WebList Select
WebRadioGroup Select

Descriptive Programming Series

  1. Descriptive Programming (DP) Concepts – 1
  2. Descriptive Programming (DP) Concepts – 2 {Regular Expressions}
  3. Descriptive Programming (DP) Concepts – 3 {Ordinal Identifiers}
  4. Descriptive Programming (DP) – 4 {Creating a Test Script)
Subscribe for Relevant Codes newsletter to get awesome updates and articles delivered straight to your inbox.

Leave a Comment

{ 136 comments… add one }

  • Prasad September 11, 2013, 12:29 am

    Perfectly explained my confusion about WebTables in web page and why we don’t include them in the code until they required. Thank you!!!

    “You might wonder why I have omitted the WebTable below the Page and above the WebEdit object. In practice, we can also skip the Page object to identify the WebEdit. But, why did I skip the WebTable after all!? When you experiment more with DP, you will discover that some objects are embedded in many WebTables, and it will become cumbersome if we were to include all WebTables in the hierarchy to get to the object of interest (thanks to the person who thought that will be a terrible idea!). “

    Reply
  • RajSekhar September 10, 2013, 6:53 am

    Hi Anshoo..
    Is there a way to click on new tab in same browser without using opennewtab() function? Can you please help me on this/ I’m trying to wrote code to open new tab using below lines getting error
    SystemUtil.Run “iexplore.exe”, “http://www.google.com”
    Set myb = Browser(“name:=Google”)
    Set mywo = myb.WinObject(“nativeclass:=client”)
    Set myt = mywo.WinButton(“nativeclass:=push button”,”acc_name:=New Tab (Ctrl+T)”).Click

    Reply
  • dilip September 6, 2013, 1:13 am

    i didn’t get why we are skipping webtable

    Reply
  • Girish kumar April 20, 2013, 12:04 am

    Hi,

    I need qtp script for the flight reservation window verify the business price is twice the economy class and also for open the flight reservation window verify the items present in the flight reservation window are alphabetically sorted.

    Reply
  • Nishant January 12, 2013, 10:54 pm

    Hi Anshoo,

    Is there a way we can parametrize the object we are checking. What I mean is can we have a function where we could pass the Obj Class Name, there by having a single function to check different object types.
    I tried doing that but its not working.

    Thanks

    Reply
  • Madhu Suthanan November 14, 2012, 9:09 am

    Really good.
    Keep on moving!!

    Reply
  • satish kunche September 26, 2012, 11:54 am

    hi,
    how to click image by using descriptive program?
    plz help me.
    i was used like…

    Browser(“name:=.*”).Page(“title:=.*”).Image(“name:=Image”, “file name:=btn_update_1.jpg”, “html tag:=IMG”, “image type:=Image Link”).Click,
    bt not working plz help me?

    Reply
    • Anshoo Arora October 10, 2012, 3:06 am

      Satish, try this:

      Browser("name:=.*").Page("title:=.*").Image("file name:=btn_update_1.jpg").Click
      

      You only need to add the required properties. Not all are required. Having more properties in the description does not guarantee robustness.

  • Lakshmanan Durairajan July 26, 2012, 4:15 am

    Well explained.

    Couple of questions:

    (1) Is it good to add the ‘Web tables’ that you omitted?
    whats the best practise?

    (2) When we spy using the ‘Object spy’, lot of ‘properties’ are shown.
    Among these properties of an object, how do we conclude that ‘specific set’ of properties can be used for Descriptive programming?

    Reply
    • Anshoo Arora July 26, 2012, 1:43 pm

      Lakshmanan: It depends. At times, it may be required to reference a ‘static’ table to reach to a ‘dynamic’ element. Other times, it may not be required. The best practice then is to make sure your script is robust, with or without the table :)

      To select the properties from the Spy, again, it depends. It comes from experience and knowledge of HTML/CSS/DOM. There are no set rules as static properties change from one object and technology to another.

  • Anonymous June 24, 2012, 5:04 pm

    Hi Anshoo,
    Could you please explain me how to write discriptive programming when AUT is not ready with an example.
    Thanks in advance,
    Anvitha

    Reply
    • Anshoo Arora June 26, 2012, 4:25 pm

      Anvitha, this is only possible if you have the design document that details the objects (and their properties) that will be present in the application once its ready. Not recommended though.

  • shwetha February 14, 2012, 5:12 am

    Hi,
    i am working on qtp. i am calling a function in my script . i have the defined objects used in my function in my script using DP.
    When i call that function i am getting the unknown error .
    But when define my objects inside the function and call that function in my script its working fine.

    Please can any one help me whats the problem with first case because i want to reuse that function in my other script.

    Reply
    • Anshoo Arora February 16, 2012, 10:48 am

      Shweta, can you please share the code you’ve written?

  • Sreeni February 13, 2012, 6:28 pm

    I have a webtable with on which i need to check all the records are in alphabetical order or not. which contains special characters to can you give me some idea how i can do that ..

    regards
    sreeni.

    Reply
  • Piyush February 3, 2012, 12:13 am

    Hi Anshoo,
    In QTP10.0 I don’t see any runtime and test object property radio button on object spy while I see native and identification property there,so how this GUI change is related to old GUI
    is native property(10.0) updated from———>runtime(old GUI)
    and identification(10.0) updated from———->test object(old GUI)
    please help me out on this.
    thanks,
    Piyush kotiyal

    Reply
    • Anshoo Arora February 13, 2012, 11:59 am

      Piyush, its a new way of naming each starting QTP 10.

      Native = Runtime
      Identification = Test Object

  • Pushkar December 25, 2011, 9:18 am

    Hi Anshoo,

    Selecting an items from a weblist populates data in another weblist. But using QTP this doesnt happen, i.e the 2nd weblist doesnt get populated. Any inputs would be appreciated.

    Reply
    • Anshoo Arora December 27, 2011, 7:30 am

      Pushkar: Try changing the ReplayType and see if that helps.

      Setting.WebPackage("ReplayType") = 2
      
      'code to select data in WebList
      
    • Pushkar December 27, 2011, 1:05 pm

      Anshoo, I tried doing this as well but the problem remains the same.

      Below is my code:

      Setting.WebPackage(“ReplayType”) = 2
      browser(“New Cars, Used Cars, Car”).Page(“New Cars, Used Cars, Car”).WebList(“drpMakeNew”).Select “Audi”
      wait 4
      browser(“New Cars, Used Cars, Car”).Page(“New Cars, Used Cars, Car”).WebList(“drpModelNew”).Select “TT”

      The ‘model’ weblist doesnt seem to get populated. (URL: carwale.com)

    • Anshoo Arora January 12, 2012, 11:24 am

      Pushkar, this seems to work:

      Browser("title:=New Cars.*").WebList("html id:=drpMakeNew").Select "Audi"
      
  • knenisarada December 23, 2011, 11:35 am

    very nice site

    Reply
  • Ramadurai November 9, 2011, 8:50 am

    Awesome tutorial. Really helped me alot

    Reply
  • hash October 19, 2011, 12:51 am

    i am trying to automate my gmail account, when i define the web element (Conpose mail), it is not working.

    i tried with the below code:

    Set ListElmt = Description.Create()
    ListElmt(“micclass”).Value = “WebElement”
    ListElmt(“innertext”).Value = “Compose mail”
    WebElement(ListElmt).click

    Please help me out of it.

    many thanks

    Reply
  • Sukhvinder October 6, 2011, 4:47 am

    I am getting ‘General Error’ when trying to retrieve the current URL in the browser address bar using DP.

    Below is the code snippet:

    strBrowserTitle = Browser(“Index:=0″).GetROProperty(“title”)
    strPageTitle = Browser(“Index:=0″).Page(“Index:=0″).GetROProperty(“title”)

    strNewURL = Browser(“title:=”&strBrowserTitle&”").Page”title:=”&strPageTitle&”").GetROProperty(“url”)

    This last line of code gives this error. Also tried the below variation but again getting the same error:

    strNewURL = Browser(“title:=”&strBrowserTitle&”").Page”title:=”&strPageTitle&”").Object.URL

    Reply
    • Anshoo Arora October 11, 2011, 4:49 pm

      Sukhvinder, do you have multiple browsers with the same title open?

    • Bala October 30, 2012, 12:48 pm

      Hi Sukhvinder,

      find the below line of code for Last line

      strNewURL = Browser(“title:=”&strBrowserTitle).Page(“title:=”&strPageTitle).Object.URL

  • chandan September 29, 2011, 2:07 am

    Hi Anshoo,

    I felt very elated going through the contents and the quality of deliveries for the queries over here.Thanks for being so cooperative.

    I was looking around for a issue using QTP DP. Is there any way to verify if a web-based application can be verified for refreshing a screen.
    The actual thing to verify is if i select an item from a drop down menu, the screen refreshes.

    Regards,
    Chandan

    Reply
    • Anshoo Arora September 29, 2011, 9:59 pm

      Chandan it may be possible. Retrieve the sourceIndex of any object on the screen, refresh it, retrieve the sourceIndex again and see if it has changed.

      sourceIndex = Browser("title:=Google").WebEdit("name:=q").Object.sourceIndex
      
      Browser("title:=Google").Refresh
      Browser("title:=Google").Sync
      
      If sourceIndex  Browser("title:=Google").WebEdit("name:=q").Object.sourceIndex Then
          MsgBox "The browser was refreshed!"
      End If
      
    • chandan September 30, 2011, 12:32 am

      Hi Anshoo,
      The solution you mentioned is not working. After refresh, Source index is not changing always. I used the following:
      sourceIndex = Browser(“title:=Google”).WebButton(“name:=Google Search”).Object.sourceIndex
      msgbox sourceIndex
      Browser(“title:=Google”).Refresh
      Browser(“title:=Google”).Sync
      sourceIndex = Browser(“title:=Google”).WebButton(“name:=Google Search”).Object.sourceIndex
      msgbox sourceIndex
      If sourceIndex = Browser(“title:=Google”).WebButton(“name:=Google Search”).Object.sourceIndex Then

      Reporter.ReportEvent micFail,”Step”,”Failed”
      else
      Reporter.ReportEvent micPass,”Step”,”Passed”
      End If

      IN both the cases, source index value is same.

    • Anshoo Arora October 11, 2011, 4:39 pm

      Chandan: maybe the Google website is not a good candidate because it works a little differently in comparison to most other websites, but you can use the above code in a loop:

      sourceIndex = Browser("title:=Google").WebButton("name:=Google Search").Object.sourceIndex
      
      Do
          Browser("title:=Google").Refresh
      
          If Not (sourceIndex = Browser("title:=Google").WebButton("name:=Google Search").Object.sourceIndex) Then
              Print "page refreshed"
          End If
      Loop
      
  • javeed September 26, 2011, 12:21 am

    hi,
    the process which you have explained above is very good and understandable for web applications but when we work with windows application how can we get the DP of the menu objects in flight reservation window can you please explain i detailed

    Reply
  • dimple September 21, 2011, 9:42 am

    How to write a code to identify an image object among objects with no innertext ?

    Reply
    • Anshoo Arora September 24, 2011, 9:35 pm

      Dimple: You can use its file name property.

    • venkatesh November 15, 2012, 7:15 am

      Hi,

      there are various properties we can use to identify imge type object such as file name/image type/html id
      if the image working as link we can use src.

      thanks

  • Roselin September 8, 2011, 5:49 am

    Good explanations! Thanks!

    Reply
  • Yuvraj September 7, 2011, 11:46 am

    Good one. Thanks.

    Reply
  • sarika August 20, 2011, 6:37 am

    this is so useful. Thanks a lot for your effort to write in such a easy language, really appreciate it.

    Many Thanks…

    Reply
  • Manikumar August 1, 2011, 11:17 pm

    Hi,,this is really helpful and very intreseting…Thanks for Posting…

    Reply
  • Shiva June 24, 2011, 12:49 am

    Hi All,

    Hi anshoo,
    The material that you have provided is excellent.Thanks alot for starting these type of forums.

    I need some help on the below one.

    Is there any one worked on oracle apps automation using QTP.

    Please let me know

    Reply
    • Anshoo Arora June 24, 2011, 11:19 am

      Shiva: Never had a chance to work with an Oracle app. You may want to try SQAForums.com – great forum!

    • Anonymous June 27, 2011, 7:41 am

      Thanks Anshoo

      I will join in SQAForums

  • suriya June 9, 2011, 2:10 am

    Hi
    I have error for dp at link object

    The “[ Link ]” object’s description matches more than one of the objects currently displayed in your application. Add additional properties to the object description in order to uniquely identify the object.

    Line (6): “browser(“name:=User Account”).page(“title:=User Account”).link(“name:=Register”).Click”.

    Tip: If the objects in your application have changed, the Maintenance Run Mode can
    help you identify and update your steps and/or the objects in your repository.

    I add another property also still this error coming on it. How to solve this? plz help

    Reply
    • Anshoo Arora June 24, 2011, 10:50 am

      Suriya: Add “index” to the Link and see if that helps. This generally happens when the object description provided is not unique.

  • Deepika April 26, 2011, 3:59 pm

    Hi Anshoo,

    QTP11 object spy is recognizing the objects in the web browser and the same with Navigate and Learn. When i click on learn button the objects are not displayed in the object repository. Please Advice.

    -Deepika

    Reply
  • Taran March 18, 2011, 4:06 am

    Hi Anshoo

    Nice work done by you.

    I have a doubt.
    QTP Object Spy recognizes web Browser as Windows Internet Explorer instead of ‘Browser’.

    Please advice.

    Thanks

    Reply
    • markQA March 20, 2011, 12:14 pm

      which IE & QTP version you are using?

    • Taran March 21, 2011, 2:12 am

      Hi MARK

      I was using IE7 and QTP10. After surfing the comments here , I came to know about patch for it. Now my problem is solved.

      Thanks.

  • Taran March 18, 2011, 4:06 am

    Hi Anshoo

    Nice work done by you.

    I have a doubt.
    QTP Object Spy recognizes web Browser as Windows Internet Explorer instead of ‘Browser’.

    Please advice.

    Thanks

    Reply
  • hari March 15, 2011, 8:13 am

    hi anshoo,
    i confused in understanding the class of an object ,how to confirm it wether it is a web element or weblist or link without using the object spy

    Reply
  • vandana March 3, 2011, 8:32 am

    Hi! Anshoo
    I was working on QTP using DP. I used the above URL to login to the application. That part worked well but after login I go to next page and create contact and that is not recognized by QTP. Can you please please help me. Here is the script I wrote:
    browser(“name:=opentaps CRM”).page(“title:=opentaps CRM”).webedit(“name:=USERNAME”,”index:=0″).set datatable.value(“Username”,”dtLogin”)
    browser(“name:=opentaps CRM”).page(“title:=opentaps CRM”).webedit(“name:=Password”).Set datatable.Value(“Password”,”dtLogin”)
    browser(“name:=opentaps CRM”).page(“title:=opentaps CRM”).webbutton(“name:=Login”).Click
    wait(20)

    browser(“name:=My Home | opentaps CRM”).page(“title:=My Home | opentaps CRM”).link(“name:=Create Contact”).Click
    browser(“name:=My Home | opentaps CRM”).page(“title:=My Home | opentaps CRM”).webedit(“name:=lastName”).Set datatable.Value(“LastName”,”dtCreateLead”)
    browser(“name:=My Home | opentaps CRM”).page(“title:=My Home | opentaps CRM”).webedit(“name:=firstName”).Set datatable.Value(“FirstName”,”dtCreateLead”)
    browser(“name:=My Home | opentaps CRM”).page(“title:=My Home | opentaps CRM”).webbutton(“name:=Create Contact”).Click
    Your website is very helpful. Thankyou so much. You are an expert..wow!!

    Reply
    • markQA March 11, 2011, 2:52 am

      Vandana, you have to regularize the browser and page title.

  • Atul December 14, 2010, 7:22 am

    Hi,
    I want to know to perfrom scripting in MACro Excel,i have a excel tool which add a addins afetr opening the Excel file and after clickin on the addins i got a list of option in the Listview and when i click on any option it open a form and in that form we have a drop down and a username and password filed like that.
    Can you please tell me wat type of scripting we have to use.

    Reply
  • Pranshu November 18, 2010, 8:34 am

    Hi Anshoo,

    Adding you into favorites, I have one question.

    Browser(“Pranshu”).Page(“Pushpam”).Image(“alt:=LogOut”,”alt:=Quitter”).Highlight
    Browser(“Pranshu”).Page(“Pushpam”).Image(“alt:=Quitter”,”alt:=LogOut”).Highlight

    LogOut is an image for English website. Quitter for French. Technically, is there any difference between the two? Will QTP find Quitter first or LogOut first, for the first line? Does it reads and finds properties(values) from Left to Right or Right to Left?

    ***If I want to highlight this image for any of the French or English sites, I would prefer it to be highlighted in one line only. Do you have any inputs for this to make that happen?

    Reply
    • Anshoo Arora December 5, 2010, 9:44 pm

      Pranshu,

      Is the ‘file name’ of the image same?

    • Pranshu December 7, 2010, 2:23 am

      Anshoo,

      English–> file name:=button_logout.gif
      French–> file name:=button_logout_fr.gif
      (This is how our developers have put the values….Assume, there’s no such property which has the same value for the image)

      1) Please tell me, what’s the behavior, how does it go?…..firstly LogOut or firstly Quitter…..for below:
      Browser(“Pranshu”).Page(“Pushpam”).Image(“alt:=LogOut”,”alt:=Quitter”).Highlight

      2) If QTP finds both the properties(values) in above case. Then lets say this is an AND method in DP. Is there any OR method too in DP?

    • Anshoo Arora December 7, 2010, 12:25 pm

      Pranshu,

      See if one of these work for different locales:

      Browser(“Pranshu”).Page(“Pushpam”).Image("file name:=button_logout.*.gif").Click
      Browser(“Pranshu”).Page(“Pushpam”).Image("file name:=button_logout.gif|button_logout_fr.gif").Click
      
    • Pranshu December 9, 2010, 5:13 am

      Anshoo,

      1st I dint check as it will work fine for sure.
      Browser(“name:=.*”).Page(“name:=.*”).Image(“alt:=LogOut|Quitter”).Highlight
      This is also absolutely working fine. Thanks very much for telling. I’m glad now :)

      And…(I find, it finds from Right to Left till the object gets uniquely identified)….take care

  • Anonymous November 9, 2010, 3:40 pm

    this i wrote for the http://www.financialvisions.com

    Browser(“”).page(“”).Image(“file name:=bt_search.gif”).click

    while running the code it does not go to the other pages

    Reply
  • Guhan October 17, 2010, 10:37 am

    /*When you experiment more with DP, you will discover that some objects are embedded in many WebTables, and it will become cumbersome if we were to include all WebTables in the hierarchy to get to the object of interest (thanks to the person who thought that will be a terrible idea!). */

    Thanks a lot, Anshoo.
    I am novice to QTP .
    I was cracking my head using Webtables because the object of my interest is embedded under various webtables as similar to the example.I gave all the properties for the webtable. But i got an error stating that QTP could not identify it .I did not reallise the fact that we don’t need to follow the hierarchy strictly.With your concept,I understood that there is no need to give as per the hierarchy (except in the case of ChildObjects to retrieve an object collection, as you have told for one reader’s reply).I removed them and i am able to do a click on t he object.

    Reply
  • Rajni Sodhi September 1, 2010, 1:06 am

    Hi Anshoo,

    Thanks so much..The article was really easy and simple to understand.You have great explanatory skills..

    Thanks again

    Reply
  • Rajni Sodhi August 12, 2010, 5:47 am

    I have tried using regular expressions for the same.But then only the first Weblist gets identified..(even if i select 2 claims)The remaining ones does not get identified.Please guide

    Reply
    • Anshoo Arora August 22, 2010, 4:32 pm

      Rajni, you may have to use Index to identify the second one. Plus, you can read the article I mentioned in my previous post.. It explains how DP can be used to create descriptions at run time, which is what your scenario looks like.

    • Anonymous August 31, 2010, 7:54 am

      Thank you Anshoo.I shall try out the way you have mentioned.

  • Rajni Sodhi August 12, 2010, 5:45 am

    Hi Anshoo,
    Great explanation. your examples are very easy to understand.I am working in QTP for the first time.
    I read your articles on Descriptive Programming.(DP Concepts 1).Really nice work.
    I ‘ll describe you the scenario.Kindly help me in doing the same.
    1) There is a weblist from which i have to Select No of claims eg.One claim/Two claim/Three Claim
    2) Depending on the Selection,the WebEdit boxes and Weblists get populated i.e.If i select One claim,One webedit and one weblist gets populated(two more webedits/weblists)
    The issue is that as all the objects(WebEdits and Weblists) have diffrent names,I have to code for all of them seperately.Is there any other approach(DP/anyother) that i can follow so that I need to write less code.
    Please help.I shall be very thankful

    Reply
    • Anshoo Arora August 22, 2010, 4:31 pm

      You can create a single loop to deal with all objects at once, depending upon how they are created. I think this article may be a little helpful to get started..

  • chaitanya June 29, 2010, 2:24 am

    Hello Anshoo!!

    Thanks for clearing my previous issue.

    Currently, I am facing a problem with my QTP script. I am using systemutil.Run method to open ie and run my web application. But, the problem is when I need to do some volume test, I am using data table. Now, when the second row of the data table is executing, due to the systemutil.Run, another browser is opening and am getting a run error. I need a solution to recover my script from this general run error.

    Thanks.

    Reply
    • Anshoo Arora July 6, 2010, 1:32 pm

      You will have to handle SystemUtil.Run with a conditional statement:

      If Environment.Value("ActionIteration") = 1 Then
          SystemUtil.Run "", ""
      End If
      

      But the above is going to be a little tricky if your test does not always start with the first iteration. For that, you may be required to store the action iteration in a variable and use that variable in your test:

      'When the test starts: in global file
      iFirstIteration = Environment.Value("ActionIteration")
      

      and within your Action:

      If Environment.Value("ActionIteration") = iFirstIteration Then
          SystemUtil.Run "", ""
      End If
      
  • chaitanya June 28, 2010, 9:10 am

    Hi anshoo!!

    I have installed QTP 9.2 on windows 7. But, QTP is not able to recognise IE as a web browser. It is showing it as a win object. The problem is same with even QTP 10.0 (trial version). Do u have any solution for this?? I even tried by registering the browser in QTP.

    Reply
    • Anshoo Arora June 28, 2010, 10:41 am

      The patch QTP_00644 must be installed on Windows 7 for QTP to work. Also, I’m not sure if QTP 9.2 is supported – you will have to install QTP 10.0.

  • Anshoo Arora June 1, 2010, 5:41 am

    Hi Dennis,

    If you open the Object Spy and for a WebElement object, if you notice the supported Operations, you will find that it does not support the Set event. Also, when building object hierarchies, you must always specify the Test Object. Either that, or replace the Test Object with an object collection of the same class.

    Reply
    • Dennis June 2, 2010, 7:04 am

      Hi, Anshoo,

      Thanks. I think your concept is useful, and then I’ve found the approach.

      I think the following code can help me to ignore to know the Test Object.

      Page(oGoogPage).ChildObjects(oGoogWebEdit)(0).Set "DP is great"
      

      But this approach has a prerequisites. That is

      ChildObjects(oGoogWebEdit)

      must be able to identify only one specified object.

      Anyway, I think this is a well workaround, and I didn’t see any risk here for now.

      Thank you again, Anshoo.

      Regards,
      Dennis

    • Anshoo Arora June 7, 2010, 8:48 am

      That’s true :)

      Its the same as using the collection object in a loop, which you see more often:

      For ix = 0 to oParent.Count - 1
          oChildObjects(ix).Highlight
      Next
      
  • Dennis May 27, 2010, 12:20 am

    Hi, Anshoo,

    I want to get a solution from you for a questions.

    Using your example:

    ' Creating Browser description
    ' "title:=Google"
    Set oGoogBrowser = Description.Create
    oGoogBrowser( "title" ).value = "Google"
     
    ' Creating Page description
    ' "title:=Google"
    Set oGoogPage = Description.Create
    oGoogPage( "title" ).Value = "Google"
     
    '* Creating WebEdit description
    ' "html tag:=INPUt", "name:=q"
    Set oGoogWebEdit = Description.Create
    oGoogWebEdit( "html tag" ).Value = "INPUT"
    oGoogWebEdit( "name" ).Value = "q"
    
    

    and then

    Browser(oGoogBrowser).Page(oGoogPage).WebEdit(oGoogWebEdit).Set "DP is great"
    

    Now, there is an assumption that we don’t know the object class of “oGoogWebEdit” is “WebEdit”, and then how can I identify it in QTP by DP?

    I have tried that

     Browser(oGoogBrowser).Page(oGoogPage).oGoogWebEdit.Set "DP is great" 

    It cannot work.

    And also I try to use the following:

     Browser(oGoogBrowser).Page(oGoogPage).WebElement(oGoogWebEdit).Set "DP is great" 

    (Because I originally realize that all the objects can be identified as WebElement.)
    even

     Browser(oGoogBrowser).Page(oGoogPage).Object(oGoogWebEdit).Set "DP is great" 

    (Because I suppose there is a “Object” class…)
    Both of them cannot work.

    Is there any solution for identify the object by DP when I don’t know the exact object class in QTP?

    Thank you in advance.

    Regards,
    Dennis

    Reply
  • Vrinda May 10, 2010, 9:49 am

    Hi Anshoo,

    Great explanation. your examples are very easy to understand. I am beginner with QTP and refer your blog for reference.
    I need your help for the following.
    Var1=Browser(” “).Page(” “).WebList(” “).Select (DataTable(“Desc”, dtGlobalSheet))
    msgbox Var1

    I have parameterised value and trying to retrieve its value using a variable and display same using message box. But cannot.
    How do i do this. Cos for further validation i need the value from table.

    Regards,
    Vrinda

    Reply
    • Anshoo Arora May 10, 2010, 10:30 am

      This statement:

      Var1=Browser("").Page("").WebList("").Select (DataTable("Desc", dtGlobalSheet))
      

      is selecting a value from the Test Object. It will not retrieve any result. To retrieve the selected value, you must use GetROProperty:

      Browser("").Page("").WebList("").Select (DataTable("Desc", dtGlobalSheet))
      Var1 = Browser("").Page("").WebList("").GetROProperty("value")
      MsgBox Var1
      
    • Vrinda May 10, 2010, 11:53 pm

      Thanks Anshoo for quick reply.

      Actually i also tried with the following method. Let me know if it is correct?
      Browser(“”).Page(“”).WebList(“”).Select DataTable(“Desc”, dtGlobalSheet)
      Var1 = Datatable.Value(“Desc”, dtGlobalSheet)
      MsgBox Var1

      Regards,
      Vrinda

    • Anshoo Arora May 12, 2010, 10:10 am

      Technically, if no error occurs, it will always work. However, if the value from the DataTable is invalid, it will certainly result in a run error. When that happens, Var1 will denote the value that *was selected*, when in reality, it was not..

  • Radhika May 10, 2010, 9:16 am

    Hi Anshoo,

    I had recorded a script using default Flight Reservation sample second’s page.
    Parameterised FromMonth and FromDay drop down. Now when running the script it is not going for 2nd iteration since click on Continue button at the end lands on next page. so not coming back to previous page.

    How should i run all the iteration.

    Note: Have started recording directly from second page so there is not login.

    Browser("Find a Flight: Mercury").Page("Find a Flight: Mercury").WebRadioGroup("tripType").Select "oneway"
    Browser("Find a Flight: Mercury").Page("Find a Flight: Mercury").WebList("passCount").Select "2"
    Browser("Find a Flight: Mercury").Page("Find a Flight: Mercury").WebList("fromPort").Select "Frankfurt"
    
    Browser("Find a Flight: Mercury").Page("Find a Flight: Mercury").WebList("fromMonth").Select DataTable("From_Month", dtGlobalSheet)
    Browser("Find a Flight: Mercury").Page("Find a Flight: Mercury").WebList("fromDay").Select DataTable("From_Day", dtGlobalSheet)
    Browser("Find a Flight: Mercury").Page("Find a Flight: Mercury").WebList("toPort").Select "New York"
    tomonth=Browser("Find a Flight: Mercury").Page("Find a Flight: Mercury").WebList("toMonth").GetROProperty("value")
    today=Browser("Find a Flight: Mercury").Page("Find a Flight: Mercury").WebList("toDay").GetROProperty("value")
    Browser("Find a Flight: Mercury").Page("Find a Flight: Mercury").WebRadioGroup("servClass").Select "Business"
    Browser("Find a Flight: Mercury").Page("Find a Flight: Mercury").WebList("airline").Select "Blue Skies Airlines"
    Browser("Find a Flight: Mercury").Page("Find a Flight: Mercury").Image("findFlights").Click 46,11
    

    Kindly help.

    Reply
    • Radhika May 10, 2010, 9:35 am

      Hey Anshoo,
      That was really a very silly question which i asked you. Sorry to bother. I should have recorded one more step at the end to return to same screen again to continue all my iterations.
      Radhika

    • Anshoo Arora May 10, 2010, 10:29 am

      You must include the code to navigate back to the Parametrized page. Please read this article: it shows how a parametrized scenario is a cyclic process beginning from Page 1 and returning back to Page 1 for the next scenario to execute.

  • Radika May 6, 2010, 9:01 am

    Hi Anshoo,

    Can you Please explain how to write script to check the default value for drop down, radio button, etc. Do we need to insert checkpoint or is there any other way.
    For eg: Drop down “Passengers” is having default value “1″
    Drop down “Departing from” is having default value “Acapulco”

    Kindly help.

    Thanks,
    Radhika

    Reply
    • Radhika May 6, 2010, 9:41 am

      Hey Anshoo,

      For the above query, I have tried the following method. Let me know if i am going wrong.
      ‘Inserted Standard Checkpoint first

      Browser("Welcome: Mercury Tours").Page("Find a Flight: Mercury").WebList("fromPort").Check CheckPoint("fromPort")
      
      'Then tried to retrieve run time value
      fromport=browser("Welcome: Mercury Tours").Page("Find a Flight: Mercury").WebList("fromPort").GetROProperty("value")
      If fromport="Acapulco" Then
      	reporter.ReportEvent micPass, "Default Drop down", "Departing from default drop down value is valid"
      	else
      	reporter.ReportEvent micFail, "Default Drop down", "Departing from default drop down value is invalid"
      End If
      

      Regards,
      Radhika

    • Anshoo Arora May 6, 2010, 2:02 pm

      Radhika,

      You have the correct idea, and after sharpening a few corners, you will be able to create great scripts!! Please see my feedback to your code above:

      Dim fromPort
      
      'As the page loads, execute these statements:
      If Browser("Welcome: Mercury Tours").Page("Find a Flight: Mercury").WebList("fromPort").Check(CheckPoint("fromPort")) Then
      	fromPort = Browser("Welcome: Mercury Tours").Page("Find a Flight: Mercury").WebList("fromPort").GetROProperty("value")
      End If
      
      'Place this code where the CheckPoint is to be performed
      If fromPort <> "" Then
      	If fromPort = "Acapulco" Then
      		Reporter.ReportEvent micPass, "Default Drop down", "Departing from default drop down value is valid"
      	Else
      		Reporter.ReportEvent micFail, "Default Drop down", "Departing from default drop down value is invalid"
      	End If
      Else
      	Reporter.ReportEvent "fromPort", "Value was not retrieved. Critical Error!"
      End If
      
    • Anshoo Arora May 6, 2010, 1:54 pm

      You can simply retrieve the “value” property as the new Page loads. This will always give you the default property. :)

    • Radhika May 7, 2010, 8:44 am

      Hey Anshoo,

      Thanks a lot….I tried your above script…….Came to know one new method…..Your words are really encouraging….:)

      Regards,
      Radhiks

  • Radhika May 6, 2010, 6:44 am

    Hi Anshoo,

    Can you please help me to understand below script with an example? It is actually checking whether elements in a Weblist are in Alphabetical Order or not.

    arrCtry=Split(Browser("name:=QTP").Page("title:=QTP").WebList("name:=select1").GetROProperty("all items"),";")
    Set objArray=DotNetFactory.CreateInstance("System.Collections.ArrayList","")
    
    For i=0 to Ubound(arrCtry)
        If arrCtry(i)"--Choose One--" Then
            objArray.Add(arrCtry(i))
        End If
    Next
    
    objArray.Sort()
    objArray.Insert 0,"--Choose One--"
    
    For j=0 to Ubound(arrCtry)
        strOuput=strOuput+objArray(j)
        strOuput=strOuput+";"
    Next
    
    If strOuput=Browser("name:=QTP").Page("title:=QTP").WebList("name:=select1").GetROProperty("all items")+";" Then
        Msgbox "The Weblist's values are sorted in alphabetical order"
    Else
        Msgbox "The Weblist's values are not sorted in alphabetical order"
    End If
    

    Thanks,
    Radhika

    Reply
    • Anshoo Arora May 6, 2010, 1:48 pm

      Hi Radhika,

      Please see the comments below:

      'There are 2 parts to the below statement:
      '1: Retrieve the 'all items' property of the list: it contains all items that are visible in the ListBox
      '2: Split above statement with the delimiter ;
      arrCtry=Split(Browser("name:=QTP").Page("title:=QTP").WebList("name:=select1").GetROProperty("all items"),";")
      
      'System.Collections.ArrayList Class: http://technet.microsoft.com/en-us/magazine/2007.01.heyscriptingguy.aspx
      Set objArray=DotNetFactory.CreateInstance("System.Collections.ArrayList","")
      
      'Looping the array created in 'arrCtry'
      'If there is a match found, add the object in the ArrayList Class(objArray)
      For i=0 to Ubound(arrCtry)
      	'If a match is found:
          If arrCtry(i) = "--Choose One--" Then
      		'Adding the object here:
              objArray.Add(arrCtry(i))
          End If
      Next
      
      'Sort the ArrayList in ascending order
      objArray.Sort()
      'Insert a new value at the very first position
      objArray.Insert 0,"--Choose One--"
      
      'Execute another loop and create a single string of values: strOutput
      'strOutput = "--Choose One--;Match1;Match2" etc.
      For j=0 to Ubound(arrCtry)
          strOuput=strOuput+objArray(j)
          strOuput=strOuput+";"
      Next
      
      'If the 'all items' property of the WebList matches the Sort operation above, then its a sorted list
      If strOuput=Browser("name:=QTP").Page("title:=QTP").WebList("name:=select1").GetROProperty("all items")+";" Then
          Msgbox "The Weblist's values are sorted in alphabetical order"
      Else
          Msgbox "The Weblist's values are not sorted in alphabetical order"
      End If
      
    • Radhika May 7, 2010, 9:10 am

      Hey Anshoo,

      Thanks for the explanation. It helped to understand.
      But am still wrong output when run the above script. It is giving “not in alphabetical order”
      Below is the code.
      Set objarray=Dotnetfactory.CreateInstance(“System.Collections.ArrayList”,”")
      For i=0 to ubound(arr)
      If arr(i)”Acapulco” Then
      objarray.add(arr(i))
      End If

      Next
      objarray.sort()
      objarray.insert 0, “Acapulco”

      For j=0 to ubound(arr)
      stroutput=stroutput+objarray(j)
      stroutput=stroutput+”;”
      Next

      Other things are same…
      Kindly help
      Radhika

    • Anshoo Arora May 10, 2010, 10:21 am

      Radhika,

      try this:

      Dim arrArray, oArrayList, sElement
       
      'Create an array with elements in Ascending Order
      arrArray = Split(Browser("title:=Find a Flight.*").WebList("name:=fromPort").GetROProperty("all items"), ";")
       
      Set oArrayList = CreateObject("System.Collections.ArrayList")
       
      For Each sElement in arrArray
          If IsNumeric(sElement) Then
      		oArrayList.Add CInt(sElement)
          Else
      		oArrayList.Add sElement
          End If
      Next
       
      'Sort Ascending
      oArrayList.Sort
      
      'Verify all elements in the Ascending array with the sorted oArrayList
      For x = LBound(arrArray) to UBound(arrArray)
      	'If the array element does not match the sorted element, then the original
              'array is not in ascending order
      	If Not arrArray(x) = oArrayList(x) Then
      		MsgBox "Not Ascending"
      		Exit For
      	End If
      Next
      

      It will only throw a MessageBox if the list is not in ascending order.

    • Boopathi November 14, 2010, 11:57 pm

      how to check whether elements in a Weblist are in Alphabetical Order or not.(descending order)

      pls help:)

    • Anshoo Arora December 5, 2010, 9:37 pm

      Boopathi, you will have to write some custom code for this, or use an ArrayList to sort and check the order. What type of data does the List contain?

  • bhavi May 4, 2010, 9:12 am

    Hi Anshoo,

    I am facing issue with Web List object in my script what happening QTP is performing this action sometime but sometimes it tires to skip this action? can you help me here please

    Browser(“S”).Page(“S”).WebList(WebListID).FireEvent “onmouseover”
    Browser(“S”).Page(“S”).WebList(WebListID).Object.Click
    Browser(“S”).Page(“S”).WebList(WebListID).Click
    Browser(“S”).Page(“S”).WebList(WebListID).FireEvent “OnClick”

    Reply
    • Anshoo Arora May 6, 2010, 1:42 pm

      Hard to say what might be happening here. Are you running your test in Fast mode? Does the issue persist in Normal mode as well?

  • puneet March 29, 2010, 10:04 am

    Hi Anshoo,

    I try doing a wildcard by indicating “CN=.*”, but that didn’t work, how can I do a wildcard on this selection statement CN is equal to the machine name so there will be different machine that wil added to so the name will change. Thanks

    SwfWindow("some window").SwfWindow("DCS").SwfWindow("Network Conduits").SwfWindow("Select Certificate").SwfListView("certificateListView").Select "CN=mc4-srv3xxx"
    
    Reply
    • Anshoo Arora March 29, 2010, 1:28 pm

      Puneet,

      Try this:

      Public Function RegexSelect(ByVal Object, ByVal sItem)
      	Dim sAllItems, oRegExp, oMatches
      
      	sAllItems = Object.GetROProperty("all items")
      
      	Set oRegExp = New RegExp
      	oRegExp.IgnoreCase = True
      	oRegExp.Pattern = ";" & sItem & ";"
      	Set oMatches = oRegExp.Execute(sAllItems)
      
      	If Not oMatches.Count > 0 Then
      		oRegExp.Pattern = ";" & sItem
      		Set oMatches = oRegExp.Execute(sAllItems)
      	End If
      
      	If Not oMatches.Count > 0 Then
      		oRegExp.Pattern = sItem & ";"
      		Set oMatches = oRegExp.Execute(sAllItems)
      	End If
      
      	If oMatches.Count > 0 Then
      		sMatch = oMatches(0)
      		sMatch = Replace(Mid(sMatch, InStrRev(sMatch, ";", Len(sMatch) - 1), Len(sMatch)), ";", "")
      		Object.Select "" & sMatch
      	End If
      End Function
      
      RegisterUserFunc "SwfListView", "RegexSelect", "RegexSelect"
      

      Usage:

      SwfWindow(“some window”).SwfWindow(“DCS”).SwfWindow(“Network Conduits”).SwfWindow(“Select Certificate”).SwfListView(“certificateListView”).RegexSelect "CN=.*"
      
  • Renu February 17, 2010, 2:02 pm

    Hi Anshoo,

    I ve small query. ” I ve generated one test script and when i copy the intire folder of this QTP script( must be along with repositories) for same test in different machine.it is throwing error.what can be the reason? pls specify

    Thanks
    Renu

    Reply
    • Anshoo Arora February 19, 2010, 2:01 am

      Hi Renu,

      What is the error message? Have you copied the contents to the same location in Machine2 from Machine1?

  • Debajit Hazarika December 14, 2009, 8:59 am

    First of all, I would like to thank and appreciate for coming up with such a nice Knowledge Resource on QTP. Great piece of work, indeed…!! I consider myself as a beginner in QTP and I am trying to learn the concept of Descriptive Programing. I found your website, read the articles and could not stop writing to you.
    The way you present things and describe them is really very neat and clear, and impressive too. I found your site very different from others as I went through many QTP sites and blogs and know what they have. Sometimes, your comments and replies are much valuable than your articles….. :) That’s really nice. Now, I know I am in right place. So, I will start firing questions to you. I am sure you would address them with the same spirit, enthusiasm and patience.
    Last but not the least, thanks for guiding beginner like me. All the best…….!!

    Regards
    Debajit

    Reply
    • Anshoo Arora December 14, 2009, 2:50 pm

      Thank you Debajit. Thank you for your kind words. I’m deeply honored. :)

      Please feel free to use the comments section of the relevant posts for your queries. I will try to answer them as quickly as possible.

      Regards,

      Anshoo

  • Anshoo Arora December 3, 2009, 4:36 pm

    After you click the cell, the exposed WebEdit should technically support the .Set statement. If that does not work for any reason, you can try this as well:

    Browser("").Page("").WebEdit("").Object.Value = "Test"
    

    Also, you can check W3Schools for a HTML DOM tutorial: http://w3schools.com/htmldom/default.asp

    Reply
  • Naresh December 3, 2009, 4:33 pm

    Hello Ashoo,

    Thnaks for the Quick Response, This has resolved my 30% of the issue,

    The Issue is Few Cells in Table are Webelements, When Double clicked, will become WebEdits, where I set the values or Edit the Values depending on test requirements. now th issue is when i use the Above DOM Concept will resolve the problem of clicking the Row and column in table, however this Dom doesnot support the Set or Type the values to those cells.

    I am New to the DOM concepts, if you can guide me to study material, i would really Appreciate the time and Effort.

    Thanks a lot
    Regards
    Naresh

    Reply
  • Naresh December 3, 2009, 2:46 pm

    Hello All,

    I am having issue with QTP

    I have a Web table which has webelements in few cells, My application has Few cells which are Webelements and when double clicked will be Web Edits,

    When i Spy the Object on each cell is shown as WebElement. however when I try to get the count the value is 0. I was wondring if we can work with Webelements in descriptive programming

    ObjectCount2 = Browser(“Browser1″).Page(“Page1:”).Frame(“main_iframe”).WebTable(“name:=CCV-100″).ChildItemCount(3,iColIndex, “WebElement”)
    Print ObjectCount2

    Please help me

    Reply
    • Anshoo Arora December 3, 2009, 3:51 pm

      Hi Naresh,

      Is the cell itself a WebElement, which is to be clicked? Or, does the cell contain an element that you click?

      If the cell itself is an element that you need to click, then you can use DOM methods instead:

      Browser("Browser1").Page("Page1:").Frame("main_iframe").WebTable("name:=CCV-100")_
          .Object.Rows(2).Cells(iColIndex-1).Click
      
  • Stefan December 2, 2009, 4:35 am

    Hi Anshoo,

    again I’m having a question. I want to set global variables I’m using for several QTP-actions, such as
    Set Google = Browser(“name:=Google”).Window(“text:=Google”)
    Now I can only use this within the same action. How can I do this, will I need to define a public class I’m calling in each action?

    Thanks, Stefan

    Reply
    • Anshoo Arora December 2, 2009, 11:28 am

      Hi Stefan,

      You can use a function library and declare the variable ‘Google’ as public within the library:

      'In the associated function library:
      Public Google
      

      This will enable all actions to have complete access to your variable/reference.

  • Stefan November 30, 2009, 5:47 am

    Hello Anshoo,

    great site and very accurately written topics and answers on questions!

    Can you please help me on something… I’m trying to work out how to refer to a webelement in a webtable by DP and a parameter as innerhtml. Maybe you have already described how to do this, but I couldn’t find it here (if so post a link, please).

    I want to use something as [...] .WebElement(“innertext:=ObjectText”).Exist
    while ObjectText is used as a parameter which I have already defined. This should be very simple to do if only I knew how to… I prefer to reference the cell text than to use an index because the text can be anywhere in the table.

    Thanks a lot, Stefan

    Reply
    • Stefan November 30, 2009, 5:54 am

      Sorry, in the example Is used I mean innertext of course, not innerhtml. In my case, innerhtml and innertext are the same anyway. This is meant as a very general question, the same problem could be a reference to a website by parameter or something else.

    • Stefan November 30, 2009, 7:02 am

      OK, found out about it…
      [...] .WebElement(”innertext:=” & ObjectText).Exist
      Not very difficult I must admit, but I first experienced that it didn’t work this way for some reason.

    • Anshoo Arora November 30, 2009, 1:18 pm

      Hi Stefan,

      I’m glad you figured it out. Whenever a value comes from a variable in a description, you will have to use the “ampersand &” character.

      :)

  • Satishkumar Dega October 29, 2009, 12:22 am

    Hi Anshoo,

    I am the beginer of QTP I want to learn Regular Expression conpet and Parameterization concept in QTP.
    What is the use of both things can u explain the things with good real time example.I need those things please help me on this.

    Reply
    • Anshoo Arora October 29, 2009, 10:15 am

      Hi Satish,

      Please see my other comment here about Regular Expressions. I am currently working on an article on Parameterization, and hopefully I will try to have it released soon.

      In the meantime, to give you a brief overview, Parameterization is a technique in which you replace an actual value or an entity with a variable. That variable in turn, retrieves values from a data-pool and uses those values to drive the automation. For example, consider the following statement:

      Browser("Google").Page("Google").WebEdit("Search").Set "Descriptive Programming"
      

      We can replace the “Descriptive Programming” bit with a Parameter:

      Browser("Google").Page("Google").WebEdit("Search").Set sText
      

      Now, in our table, we can have the following structure:

      Search Text
      Descriptive Programming
      Regular Expressions

      Therefore, the first time our code executed, sText will take “Descriptive Progamming” as input and write that value to our Search Box. In the 2nd iteration, Regular Expressions will be written.

      I hope this helps..

  • Pragya October 27, 2009, 12:16 am

    Hello Anshoo

    M here to trouble you again with a very annoying query of mine.

    See this website :–> http://in.buzz.yahoo.com/ In this website, you will see a Yahoo logo image at the top. I am not able to click this logo using descriptive Programming though I am able to do so with the help of Object Repository. I tried various combinations but nothing worked. I am using QTP 9.2 with IE 7.

    This is the code I tried:

    Browser(“micclass:=Browser”).Page(“micclass:=Page”).Image(“html tag:=IMG”,”image type:=Image Link”,”alt:=Yahoo! Buzz India (TM)”).Click

    It didnt worked. When I record on this image, the learned/mandatory properties are these three only . I am really confused what to do…

    Reply
    • Anshoo Arora October 27, 2009, 8:40 am

      HI Pragya,

      You can try any of the solutions below:

      Browser("title:=.*Buzzing.*").Image("file name:=buzz_logo_.*").Highlight
      
      Browser("title:=.*Buzzing.*").Image("file name:=buzz_logo_tm_in_033109.gif").Highlight
      
      Browser("title:=.*Buzzing.*").Image("alt:=Yahoo! Buzz India \(TM\)").Highlight
      
      Browser("title:=.*Buzzing.*").Image("name:=Image", "index:=0").Highlight
      

      I hope this helps :)

  • Kiran September 22, 2009, 9:53 pm

    Hi Anshoo,
    In search of Recovery Scenario i have gone through many forums and blogs but could only find the all-known pop up error handling.And also i found all the forums and blogs have almost same topics and examples about the QTP.
    If you can provide video tutorials,with real time issues, that will be a great help for the visitors.Thanks for the reply!
    I haven’t tried it yet but will let you know the outcome once done.

    Have a nice time
    Kiran

    Reply
    • Anshoo Arora September 22, 2009, 10:18 pm

      Sure, Kiran. I will try my best to help you.

    • Anshoo Arora October 23, 2009, 10:40 pm

      Hi Kiran,

      An article on Recovery Scenarios has been published here a few days ago. I thought you might be interested.

      I was not able to record a video, but I have included several snapshots to try to cover up the visual component. Hope you like it. :)

  • Kiran September 20, 2009, 9:34 pm

    The reason why i said so is that we never had a situation other than handling the pop-ups.Let me assume that IE crashes while performing a DD testing.Suppose IE crashes at TestIteration no 50 and still 40 to finish.Will the script execute from 51 or 1? How to overcome such issues?
    And also as we are unsure where exactly this might occur,we need to instruct the QuickTest to check on every line in the script for recovery which degrades the Tool performance.Doesn’t it?
    I am elaborating this topic so that i can get a clear idea about recovery scenario. Thanks for the reply.

    Kiran

    Reply
    • Anshoo Arora September 21, 2009, 7:46 pm

      Hi Kiran,

      I appreciate your interest in learning more, and making your concepts clear.

      Will the script execute from 51 or 1? How to overcome such issues?

      In such a case, you have the following 6 possible steps to choose from:

      1. Repeat current step and continue
      2. Proceed to next step
      3. Proceed to next action or component iteration
      4. Proceed to next test iteration
      5. Restart current test run
      6. Stop the test run

      In other words, you can choose any of the 6 possible choices above. If you would like to exit, then you can do that as well.

      we need to instruct the QuickTest to check on every line in the script for recovery which degrades the Tool performance.Doesn’t it?

      Technically, we don’t instruct QTP how to use the Recovery Scenario, we just tell it what should trigger it. QTP finds if an application state matches with what we have in our scenario and activates the trigger.

      As for performance, it may impact it, but by only a little, I hope. They’re triggered only when QuickTest encounters a particular application behavior. You may be correct in saying that QTP may check after each executed line whether to trigger the Recover Scenario or not. However, I’m not too sure about this. Possibly someone at HP can answer this for us.

      I am elaborating this topic so that i can get a clear idea about recovery scenario.

      That’s great, Kiran. I feel I should learn more about Recovery Scenarios myself. Clearly, my knowledge on this subject is not vast enough to answer your questions accurately. This is going to be an action item, then!

  • Kiran September 20, 2009, 12:55 pm

    Greetings !
    I appreciate the work being done by you for the QuickTest newbie’s.Anshoo,as a member of AdvancedQTP forum, your solutions for the queries are very simple and easily understandable even for the newcomers. Great Job!
    Please make me clear with the Recovery Scenario.
    As every tester wants the script to be continued after particular recovery event has been handled then why don’t they use “If then else” instead of a calling a .vbs or instead of using a recovery manager.
    When ,How and Where should i use recovery scenario.

    Have a nice time
    Kiran

    Reply
    • Anshoo Arora September 20, 2009, 4:12 pm

      When using Conditional Statements, you know that might happen here, and create conditions to tackle expected behavior of the application. For example, you may create the following Conditional Statement:

      If Browser("").Page("").WebEdit("").Exist(0) Then
          Reporter.ReportEvent micPass, "WebEdit", "The WebEdit was found!"
      Else
          Reporter.ReportEvent micFail, "WebEdit", "The WebEdit was not found!"
      End If
      

      Above, you know that there can be only 2 conditions for the WebEdit – that it exists, or it does not.

      The same cannot be said when using Recovery Scenario. The reason why they’re called Recovery Scenarios is that, they help us Recover from something we do not expect. For example, you’re running a script and IE crashes. What do you do now? If you have a Click event right after IE shuts, QTP will throw a run-time error and your script will stop. This is where you may want to use a Recovery Scenario because you’re trying to handle an error that you would not normally expect.

      The above example may be an extreme case, but I hope it clarifies the main difference between the two. One is where you expect what might happen, whereas, the other helps you overcome an issue that you would not normally expect to occur during run-time.

      I hope this helps. If you’re still unclear, or have another question after reading my reply above, please feel free to ask! :)

      Anshoo

  • Pooja September 20, 2009, 5:57 am

    Hi Anshoo ….

    I read ur articles and codes which u gave , they are really very good …. it seems that ur expert in QTP….
    I’m learning QTP these days … i hope u can provide help on that.

    Thanks

    Reply
    • Anshoo Arora September 20, 2009, 4:04 pm

      Thanks! :)

      Please feel free to ask any questions that you may have. I will try my best to help you.

  • vikas August 31, 2009, 2:24 am

    Hi Anshoo,
    Your knowledge and the way , you explained the things, just great. really really fantastic…
    There are so many sites and blogs , explaining all these kind of QTP stuffs, but your’s I found different.

    Reply
    • Anshoo Arora September 4, 2009, 5:20 pm

      Thank you, Vikas. I’m very glad that you found it useful. Likewise, if you saw some areas needing improvement, please do let me know. :)

      Thanks- Anshoo

  • Shivani August 26, 2009, 7:17 am

    Thanx for the explanation..Your answer is really satisfying for me.. Thank you so much Anshoo..

    Reply
  • Anshoo Arora August 25, 2009, 9:52 pm

    Excellent question, Shivani! You’re the first one to catch that.

    .. and to be honest with you, its one that’s quite hard to answer. Performance wise, there is a negligible difference between the 2 techniques. Usage wise, they both work quite well and are equally readable. That is, the reader can always make out what the script is doing between both methods.

    Therefore, in the end, it bottles down to personal preference. I use the 2nd one in your post 90% of the time, and I have not yet come across a situation when it failed to work. But, please note that when you are using ChildObjects to retrieve an object collection, you must specify the complete hierarchy:

    Set colLinks = Browser( "" ).Page( "" ).ChildObjects(oLink)

    Other than that, I guess its just a personal preference. If you browse other QTP sites/forums, you will see the first approach used the most. I know this answer isn’t satisfying, but I hope you will be able to choose one that you would like to use extensively. :)

    Reply
  • Shivani August 25, 2009, 12:04 am

    One more doubt in your article..

    You have mentioned: We can skip the Page object..So which is the best coding method

    Browser().Page().WebEdit().Set ""

    OR

    Browser().WebEdit().Set ""

    Is there any particular case where we can say First method is the best one and also the case where we can say second method is the best one?

    Reply
  • Shivani August 24, 2009, 11:11 pm

    Hi Anshoo,

    Doubt cleared :)

    Reply
  • Anshoo Arora August 24, 2009, 4:55 pm

    Hi Shivani,

    If your test contains both Shared and Local Object Repositories, then:

    1. Your Local Repositories will be transferred to the local repository of each action in the test, as mentioned in the first bullet point.
    2. Your Shared Repositories will be associated with the same test, but since you also have Local Repositories, in your case, your Local Repositories won’t be empty. They will contain information from #1 above.

    I hope this will clarify your doubt. :)

    -Anshoo

    Reply
  • Shivani August 24, 2009, 7:11 am

    Hello Anshoo,

    You seems to be another expert in the field of QTP and I am deeply impressed by your posts which truly represents your vast experience along with your expertise. I have a question for your that may sound silly to you( as I am a QTP beginner). Still m taking courage to ask: I read in the QTP help file that :

    ###########################################################
    Note for users of previous QuickTest versions: When you open a test that
    was created using a version of QuickTest earlier than version 9.1, you are
    asked whether you want to convert it or view it in read-only format.
    Whether you choose to open it in read-only format or convert it, the object
    repositories are associated to the test as follows:
    ➤ If the test previously used per-action repositories, the objects in each
    per-action repository are transferred to the local object repository of each
    action in the test.
    ➤ If the test previously used a shared object repository, the same shared
    object repository is associated with each of the actions in the test, and
    the local object repository is empty.
    #############################################################

    I have a doubt in the second point. What if my test created in a previous version (say QTP 9.0 ) contains both Local and Shared OR. So as per the second point will be Local OR will get deleted as it is saying the local OR is empty??

    Regards,
    Shivani

    Reply
  • Anshoo Arora August 11, 2009, 9:21 pm

    Thanks! :)

    Reply
    • qtpuser November 9, 2010, 10:51 am

      Hi, this is really a great initiative. I came across this and liked it very much. I am new to QTP and started looking in DP.
      While implementing above code I came across two things.
      1. For WebEdit class, if I use this: WebEdit( “name:=q,”html tag:=INPUT” ), I get an error, parentesis is not allowed while calling sub.
      2. When I removed name:=q and check the syntax, syntax is valid but when I run the script, I get error.
      ( General run error).
      This is what i am trying
      Browser(“title:=Google”)
      Page(“title:=Google”)
      WebEdit( “html tag:=INPUT” )
      Browser(“title:=Google”).Page(“title:=Google”).WebEdit( “html tag:=INPUT” ).Set “DP”
      Browser(“title:=Google”).Page(“title:=Google”).WebButton(“name:=Google Search”).Click

    • Anshoo Arora November 14, 2010, 5:33 pm

      WebEdit( “name:=q,”html tag:=INPUT” ) should be written the following way:

      .WebEdit(“name:=q”, “html tag:=INPUT”)

      Notice the quotation marks after ‘name:=q’.

  • Gautami August 11, 2009, 9:21 pm

    Your introduction to Descriptive Programming is awesome! It is concise, well-explained and I found it really helpful.

    Thanks

    Reply