Tuesday, May 6, 2014

Getting Standard/Inner Text

The code below shows how you can get the text from any standard object using diff way

Standard Examples
'Get text from a ListView - report style (for example, Windows Explorer)
Msgbox Window("C:\Program Files\Mercury").WinListView("SysListView32").GetSubItem(1,2)

'Get text from a toolbar
Msgbox Window("C:\Program Files\Mercury").WinToolbar("ToolbarWindow32").GetItem(1)

'Text of a message-box, the Static control is not in the object repository/shared object ' 'repository
set StatObj = Dialog("DlgTB").Dialog("DlgTB").Static("nativeclass:=Static","Index:=1")
Msgbox StatObj.GetROProperty("text")

Web Example
' An example for a Web Table (in the Mercury Tour site)
Set Cell = Browser("Welcome: Mercury Tours").Page("Select a Flight: Mercury").WebTable("RETURN").ChildItem(3, 2, "WebElement", 0)
Msgbox Cell.GetROProperty("innertext")

Visual Basic Example
'Retrieving the text of a label in a VB form: (There is no Test Object for a label)
Msgbox VbWindow("VBForm1").Object.Controls("Label1").caption

.NET Example
'Get the text of items in a CheckListBox (has no Test Object)
'Get run-time object reference
Set CustList = SwfWindow("Win").SwfObject(ìlst").Object

'Get Items collection
Set ListItems = CustList.get_Items()

'Get Items count
ItemsCount = ListItems.Count

'Loop over all items
For i = 0 to ItemsCount-1
text = text & ListItems.Item(i)
Next

ActiveX Example
This example will retrieve the text from the Visual Basic Flight 1A sample application's flight grid
This retrieves the flight number from the 3rd row.

VbWindow("VbWindow").VbWindow("VbWindow").AcxTable("Grid Control").Object.Row = 3
VbWindow("VbWindow").VbWindow("VbWindow").AcxTable("Grid Control").Object.Col = 0

Msgbox VbWindow("VbWindow").VbWindow("VbWindow").AcxTable("Grid Control").Object.Text

Count & Close All Browsers

QTP Script to get total count, names of all open browsers and to close them using descriptive programming.

Set ab=Description.Create
ab("micclass").value="Browser"
Set obj=Desktop.ChildObjects(ab)
Msgbox obj.count
For i=0 to obj.count-1
                c=obj(i).getroproperty("name")
                Msgbox(c)
                obj(i).Close

Next