Wednesday 31 July 2013

QTP :- What is Objects Collection object, How do we refer to an item in objects collection, How do we send keyboard input?

Object Collection - It is a generic term and not a keyword. This is something like an array that holds a collection of objects.. So its an array of objects..
How do you refer to an item in it - Since this is an array, it will be accessed the same way you do for an array, i.e. bu using its index.

Example: Assume you have a page with 20 links where the link text and URL are dynamically loaded. Suppose you want always have to click the 7th link.. Code is as follows -
Set oDesc = Description.Create
oDesc("micclass").Value = "Link"
Set oAllLinks = Browser("").Page("").ChildObjects(oDesc)  'Here oAllLinks is the collection of Objects
'Click on 7th link
oAllLinks(6).Click     'Array index starts from 0. So index 6 is used

Sending Keyboard Input - This can be done using SendKeys command. Code is as follows -

Set WshShell = CreateObject(“WScript.Shell”)
WshShell.SendKeys "hp quicktest professional"

No comments:

Post a Comment