QTP General Functions to Define Web Objects

While automating a web application, we encounter objects which are used again and again. We can always add them to out object repository, but iy would make the repository very bulky as the same object would be needed to add for each page.

To solve this issue, we can use following functions in the function library to define web objects.

   1: 'Functions for creating objects for web page
   2: Function WebObjects(Page, MicClass)
   3:     Set Desc = Description.Create()
   4:     Desc("micclass").Value = MicClass
   5:     Set WebObjects = Page.ChildObjects(Desc)
 
   6: End Function
   7: 'Function:Create webedit object
   8: Function WebEditObjects(Page)
   9:     Set WebEditObjects = WebObjects(Page, "WebEdit")
  10: End Function 
 
  11: 'Function:Create webbutton object
  12: Function WebButtonObjects(Page)
  13:     Set WebButtonObjects = WebObjects(Page, "WebButton")
  14: End Function
  
  15: 'Function:Create link object
  16: Function WebLinkObjects(Page)
  17:     Set WebLinkObjects = WebObjects(Page, "Link")
  18: End Function
 
  19: 'Function:Create image object
  20: Function WebImageObjects(Page)
  21:     Set WebImageObjects = WebObjects(Page, "Image")
  22: End Function
  
  23: 'Function:Create radiogroup object
  24: Function WebRadioObjects(Page)
  25:     Set WebRadioObjects = WebObjects(Page, "WebRadioGroup")
  26: End Function
  
  27: 'Function:Create weblist object
  28: Function WebListObjects(Page)
  29:     Set WebListObjects = WebObjects(Page, "WebList")
  30: End Function
 
  31: 'Function:Create webtable object
  32: Function WebTableObjects(Page)
  33:     Set WebTableObjects = WebObjects(Page, "WebTable")
  34: End Function
 
  35: 'Function:Create  WebCheckBox object
  36: Function WebCheckBoxObjects(Page)
  37:     Set WebCheckBoxObjects = WebObjects(Page, "WebCheckBox") 
  38: End Function

The above functions can be called as per below examples:-

   1: Value1 = "Delhi"
   2: Set oPage=Browser("Browser").Page("PageName")
   3: Set Lists=WebListObjects(oPage)
 
   4: Lists(0).select Value1

   5: Set Edits=WebEditObjects(oPage)
   6: Edits(9).set "test"
  
   7: Set RadioButton=WebRadioObjects(oPage)
   8: RadioButton(12).select "#0"
 

   9: set CheckBox=WebCheckBoxObjects(oPage)
  10: CheckBox(i).Set "ON"