SwfListView Object
Description
A .NET Windows Forms ListView control.
IMPORTANT
You can check or output both the content and properties of a SwfListView object. For example, you can check that a specified value is displayed in a certain cell or retrieve the value located in a certain cell. You can also check that the object has the expected number of rows and columns.
When you insert a standard checkpoint or output value on a SwfListView object, the Define Row Range dialog box opens, enabling you to select the range of rows you want to include in your checkpoint or output value step. After you define the row range, the Table Checkpoint Properties or Table Output Value Properties dialog box opens, enabling you to check or output the content and properties of your SwfListView object (instead of just the properties, as in standard checkpoints and output values).
Operations
The sections below list the built-in methods and properties that you can use as operations for the SwfListView object.
Note: You can also view a list and descriptions of the SwfListView description properties, for use in object repository descriptions, programmatic descriptions, checkpoint and output value steps, and as argument values for the GetTOProperty and GetROProperty methods.
Methods
Activate | Activates (double-clicks) an item in the list. |
CaptureBitmap | Saves a screen capture of the object as a .png or .bmp image using the specified file name. |
Check | Checks whether the actual value of an item matches the expected value. |
CheckProperty | Checks whether the actual value of the specified object property matches the specified expected value within the specified timeout. |
ChildObjects | Returns the collection of child objects contained within the object. |
GetAllROProperties | Returns the collection of properties and current values from the object in the application. |
Click | Clicks an object. |
ColumnCount | Returns the number of columns in a ListView object. |
DblClick | Double-clicks an object |
Deselect | Deselects an item in the list. |
Drag | Performs the 'drag' part of a drag-and-drop operation. |
DragItem | Performs the 'drag' part of a drag-and-drop operation. |
Drop | Performs the 'drop' part of a drag-and-drop operation. |
DropOnItem | Performs the 'drop' part of a drag-and-drop operation by dropping the item onto a specified target item. |
EditLabel | Activates the edit mode for an object list item for the purpose of renaming it. |
ExtendSelect | Selects an additional item from a multi-selection list. |
FireEvent | Simulates an event on a .NET object. |
GetCheckMarks | Retrieves a string containing the indexes of the selected items, separated by a semicolon (;). |
GetColumnHeader | Returns the text header of a (report-style) ListView column. |
GetContent | Returns all of the items in the list. |
GetErrorProviderText | Returns the tooltip text of the error icon associated with the object. |
GetItem | Returns the value of the item specified by the index. |
GetItemProperty | Returns the current value of a property for an item in the ListView list. |
GetItemsCount | Returns the number of items in the list. |
GetROProperty | Returns the current value of the description property from the object in the application. |
GetSelection | Returns all of the selected items in the list. |
GetSubItem | Returns the text value of a report-style (LVS_REPORT) ListView subitem. |
GetTextLocation | Checks whether the specified text string is contained in the specified window area. |
GetTOProperties | Returns the collection of properties and values used to identify the object. |
GetTOProperty | Returns the value of the specified description property from the test object description. |
Highlight | Highlights the object in the application. |
GetVisibleText | Returns the text from the specified area. |
MouseMove | Moves the mouse pointer to the designated position over the object. |
Output | Retrieves the current value of an item and stores it in a specified location. |
RefreshObject | Instructs UFT One to re-identify the object in the application the next time a step refers to this object. |
Select | Selects an item from the list. |
SelectRange | Selects all list items between (and including) two specified items. |
SetItemState | Sets the state of the check box for a specified ListView item. |
SetTOProperty | Sets the value of the specified description property in the test object description. |
ToString | Returns a string that represents the test object. |
Type | Types the specified string in the object. |
WaitProperty | Waits until the specified object property achieves the specified value or exceeds the specified timeout before continuing to the next step. |
Properties
Exist | Checks whether the object currently exists in the open application. |
Object | Accesses the native methods and properties of the object. |
Activate Method
Description
Activates (double-clicks) an item in the list.
Syntax
object.Activate Item, [BUTTON]
Arguments
Parameter | Description |
---|---|
Item |
Required. A Variant. The item to select from the list-view control. The item value (with quotes) or numeric index (without quotes) can denote the item. The first item in a list-view control is numbered 0. |
BUTTON |
Optional. A predefined constant or number. The mouse button used to click the object. Default value = micLeftBtn |
Return Type
None
Example
'The following example uses the Activate method to double-click the "Nancy" item in the "Names" list. SwfWindow("Form1").SwfListView("Names").Activate "Nancy"
Click Method
Description
Clicks an object.
Syntax
object.Click [X], [Y], [BUTTON]
Arguments
Parameter | Description |
---|---|
X |
Optional. An integer value. The x-coordinate of the click. Note that the specified coordinates are relative to the upper left corner of the object. The default value is the center of the object. Default value = -9999 |
Y |
Optional. An integer value. The y-coordinate of the click. Note that the specified coordinates are relative to the upper left corner of the object. The default value is the center of the object. Tip: You can enter micNoCoordinate for the x and y argument values if you want to enter a value for the button argument without specifying x- and y- coordinates for the click. Default value = -9999 |
BUTTON |
Optional. A predefined constant or number. The mouse button used to click the object. Default value = micLeftBtn |
Return Type
None
Example
'The following example uses the Click method to click a right mouse button at coordinates 47, 131 on the "button4" 'button. SwfWindow("Form1").SwfButton("button4").Click 47, 131, 1
ColumnCount Method
Description
Returns the number of columns in a ListView object.
Syntax
object.ColumnCount
Return Type
A long integer value.
IMPORTANT
If you perform this method on a non-report-style list, it is always treated as a list with a single column, and the value 1 is returned.
Example
'The following example uses the ColumnCount method to return the number of columns in the "ListView" object, and 'then retrieve the text header for each column. cColumns = .ColumnCount() sReport = "" For iColumn = 0 To cColumns - 1 sReport = sReport & SwfWindow("dotNet MDI").SwfWindow("dotNET ListView").SwfListView("listView1").GetColumnHeader(iColumn) & " | " Next Reporter.ReportEvent EVENTSTATUS_GENERAL, "SwfListView columns", sReport
DblClick Method
Description
Double-clicks an object
Syntax
object.DblClick X, Y, [BUTTON]
Arguments
Parameter | Description |
---|---|
X |
Required. An integer value. The x-coordinate of the double-click. Note that the specified coordinates are relative to the upper left corner of the object. |
Y |
Required. An integer value. The y-coordinate of the double-click. Note that the specified coordinates are relative to the upper left corner of the object. |
BUTTON |
Optional. A predefined constant or number. The mouse button used to double-click the object. Default value = micLeftBtn |
Return Type
None
Example
'The following example uses the DblClick method to double-click a right mouse button at coordinates 73, 120 on 'the "Test" window. SwfWindow("Test").DblClick 73, 120, 1
Deselect Method
Description
Deselects an item in the list.
Syntax
object.Deselect Item
Arguments
Parameter | Description |
---|---|
Item |
Required. A Variant. The item to deselect from the list-view control. The item value (with quotes) or numeric index (without quotes) can denote the item. The first item in a list-view control is numbered 0. |
Return Type
None
IMPORTANT
The object's SelectionMode property must be set to Multiple.
Example
Function DeselectAll(ListViewObject) Dim lastItem, curItem, strDeselected ' Deselect all selected items in the list ' List index is 0-based lastItem = ListViewObject.GetItemsCount - 1 ' Iterate through the list and deselect all selected items For curItem = 0 To lastItem ItemSelected = ListViewObject.GetITemProperty(curItem, "selected") If ItemSelected Then ListViewObject.Deselect (curItem) itemText = ListViewObject.GetITemProperty(curItem, "text") ' Verify deselection ItemSelected = ListViewObject.GetITemProperty(curItem, "selected") If Not ItemSelected Then strDeselected = _ strDeselected & " Deselected item -> " & itemText & vbCrLf Else strDeselected = _ strDeselected & " * Failed to deselect item -> " & itemText & vbCrLf End If End If Next DeselectAll = strDeselected 'Use example: ' Set ListViewObject = SwfWindow("dotNET ListView").SwfListView("listView1") ' Print (DeselectAll(ListViewObject))
'The following example uses the Deselect method to deselect the "Nancy" item from the "Names" list. SwfWindow("Form1").SwfListView("Names").Deselect "Nancy"
Drag Method
Description
Performs the 'drag' part of a drag-and-drop operation.
Syntax
object.Drag X, Y, [BUTTON]
Arguments
Parameter | Description |
---|---|
X |
Required. An integer value. The coordinates within the window from which the object is dragged. Note that the specified coordinates are relative to the upper left corner of the object. |
Y |
Required. An integer value. The coordinates within the window from which the object is dragged. Note that the specified coordinates are relative to the upper left corner of the object. |
BUTTON |
Optional. A predefined constant or number. The mouse button used to drag the object. Default value = micLeftBtn |
Return Type
None
Example
'The following example uses the Drag method to drag the object from coordinates 10, 20 within the "Test" window, 'to coordinates 30, 40 within the "OtherWindow". SwfWindow("Test").Drag 10, 20 SwfWindow("OtherWindow").Drop 30, 40 'or, within the same window: SwfWindow("Test").Drag 10, 20 SwfWindow("Test").Drop 30, 40
DragItem Method
Description
Performs the 'drag' part of a drag-and-drop operation.
Syntax
object.DragItem (Item, [BUTTON])
Arguments
Parameter | Description |
---|---|
Item |
Required. A Variant. The list-view control item to drag. The logical name (with quotes) or numeric index (without quotes) can denote the item. The first item in a list-view control is numbered 0. |
BUTTON |
Optional. A predefined constant or number. The mouse button used to click the list-view control. Note: The same button must be used in both the DragItem and DropOnItem parts of the drag and drop operation. Default value = micLeftBtn |
Return Type
None.
IMPORTANT
A DragItem statement must be followed by a Drop or DropOnItem statement.
Example
'The following example uses the DragItem method to drag the "item1" item in the list and drop it at coordinates '10, 15. SwfWindow("Form1").SwfListView("Names").DragItem "item1" SwfWindow("Form1").SwfListView("Names").Drop 10, 15
Drop Method
Description
Performs the 'drop' part of a drag-and-drop operation.
Syntax
object.Drop X, Y, [BUTTON]
Arguments
Parameter | Description |
---|---|
X |
Required. An integer value. The coordinates of the object onto which the object is dropped. Note that the specified coordinates are relative to the upper left corner of the object. |
Y |
Required. An integer value. The coordinates of the object onto which the object is dropped. Note that the specified coordinates are relative to the upper left corner of the object. |
BUTTON |
Optional. A predefined constant or number. The button that is released to drop the object. Default value = micLeftBtn |
Return Type
None
Example
'The following example uses the Drop method to drop the object at coordinates 30, 40 within the "OtherWindow" after 'dragging from coordinates 10, 20 within the "Test" window. SwfWindow("Test").Drag 10, 20 SwfWindow("OtherWindow").Drop 30, 40 'or, within the same window: SwfWindow("Test").Drag 10, 20 SwfWindow("Test").Drop 30, 40
DropOnItem Method
Description
Performs the 'drop' part of a drag-and-drop operation by dropping the item onto a specified target item.
Syntax
object.DropOnItem (TargetItem, [BUTTON])
Arguments
Parameter | Description |
---|---|
TargetItem |
Required. A Variant. The list-view control item on which to drop the dragged list-view control item. The logical name (with quotes) or numeric index (without quotes) can denote the item. The first item in a list-view control is numbered 0. |
BUTTON |
Optional. A predefined constant or number. The mouse button used to click the object. Note: The same button must be used in both the DragItem and DropOnItem parts of the drag and drop operation. Default value = micLeftBtn |
Return Type
None.
IMPORTANT
A DropOnItem statement must be preceded by a Drag or DragItem statement.
Example
'The following example uses the DropOnItem method to drag the item located at coordinates 55, 11 in the list 'and drop the item onto "item32" within the list. SwfWindow("Form1").SwfListView("Names").Drag 55, 11 SwfWindow("Form1").SwfListView("Names").DropOnItem "item32"
EditLabel Method
Description
Activates the edit mode for an object list item for the purpose of renaming it.
Syntax
object.EditLabel (Item)
Arguments
Parameter | Description |
---|---|
Item |
Required. A Variant. The list-view control item to edit. The item value (with quotes) or numeric index (without quotes) can denote the item. The first item in a list-view control is numbered 0. |
Return Type
None.
IMPORTANT
This method only enables the item for renaming. To actually rename the item, you must set its value using the WinEdit or WinEditor test object, together with an applicable method, such as Set or SetCaretPos+Type.
Example
'The following example uses the EditLabel method to activate the edit mode for the "OldName" item. The example then 'uses the Set method to change the name of the item to "NewName". SwfWindow("Form1").SwfListView("ListView1").Select "OldName" SwfWindow("Form1").SwfListView("ListView1").EditLabel "OldName" SwfWindow("Form1").SwfListView("ListView1").WinEditor("Edit").Type "NewName"
ExtendSelect Method
Description
Selects an additional item from a multi-selection list.
Syntax
object.ExtendSelect Item
Arguments
Parameter | Description |
---|---|
Item |
Required. A Variant. The item to select from the list-view control. The item value (with quotes) or numeric index (without quotes) can denote the item. The first item in a list-view control is numbered 0. |
Return Type
None
Example
'The following example uses the ExtendSelect method to select Angela from a multiple-selection list. SwfWindow("Form1").SwfListView("Names").ExtendSelect "Angela
FireEvent Method
Description
Simulates an event on a .NET object.
Syntax
object.FireEvent (EventName)
Arguments
Parameter | Description |
---|---|
EventName |
Required. A Variant. The name of the event to simulate. The list of possible events depends on the object. |
Required. None The Args argument is passed to the constructor of the event's EventArgs object or the implementing class. Enter the values in a comma separated list. If no event arguments are required, you do not need to supply a value for the argument. |
Return Type
None.
IMPORTANT
The event is sent to all listeners of the .NET object and does not affect the .NET object itself. For example, simulating a click event does not actually perform the click.
Example
'The following example uses the FireEvent method to simulate a Click event on the "Save" button. SwfWindow("Welcome").SwfButton("Save").FireEvent "Click"
GetCheckMarks Method
Description
Retrieves a string containing the indexes of the selected items, separated by a semicolon (;).
Syntax
object.GetCheckMarks
Return Type
A String value.
IMPORTANT
You can use this method only for list-view controls with 1000 or fewer items.
Example
Function datesOfMarkedItems() 'Get the dates for the selected items in the list ' Specify the column number for Date in report-style mode. date_subitem_number = 1 'Get the indexes of the selected items checkMarks = _ SwfWindow("dotNET ListView").SwfListView("listView1").GetCheckMarks 'Convert the list to an array aCheckMarks = Split(checkMarks, ";") 'Add the label and date of each selected item to the output string For curItem = 0 To UBound(aCheckMarks) curItemNumber = CInt(aCheckMarks(curItem)) itemDate = _ SwfWindow("dotNET ListView").SwfListView("listView1").GetSubItem(curItemNumber, date_subitem_number) curItemLabel = _ SwfWindow("dotNET ListView").SwfListView("listView1").GetItem(curItemNumber) strReturn = _ strReturn & "Item : " & curItemLabel & " date : " & itemDate & vbCrLf Next datesOfMarkedItems = strReturn 'Use example: ' reporter.ReportEvent micDone, _ ' "Retrieved Date for all Items selected items", datesOfMarkedItems End Function
GetColumnHeader Method
Description
Returns the text header of a (report-style) ListView column.
Syntax
object.GetColumnHeader (Column)
Arguments
Parameter | Description |
---|---|
Column |
Required. A Variant. The list-view control column whose header text you want to retrieve. |
Return Type
A String value.
Example
'The following example uses the GetColumnHeader method to return the number of columns in the "ListView" object, 'and then retrieve the text header for each column. cColumns = .ColumnCount() sReport = "" For iColumn = 0 To cColumns - 1 sReport = sReport & SwfWindow("dotNet MDI").SwfWindow("dotNET ListView").SwfListView("listView1").GetColumnHeader(iColumn) & " | " Next Reporter.ReportEvent EVENTSTATUS_GENERAL, "SwfListView columns", sReport
GetContent Method
Description
Returns all of the items in the list.
Syntax
object.GetContent
Return Type
A String value.
IMPORTANT
The returned string contains all of the items in the list-view control separated by line feed characters.
You can use this method only for list-view controls with 1000 or fewer items.
Example
'The following example uses the GetContent method to return the items in the "Names" list. MsgBox SwfWindow("Form1").SwfListView("listBox1").GetContent
GetErrorProviderText Method
Description
Returns the tooltip text of the error icon associated with the object.
Syntax
object.GetErrorProviderText
Return Type
A String value.
If no error provider control currently exists for the object, the method returns an empty string.
Example
'The following example enters some text into an edit box and then uses the 'GetErrorProviderText method to check whether the edit box has an error icon. 'If the method returns a value other than an empty string, then there is an 'error, so the Cancel button is clicked in the dialog box. If the string is empty, ' then there is no error and the Apply button is clicked. SwfWindow("Form1").SwfEdit("Ex_textBox").Set Text Dim ErrorMessage ErrorMessage = SwfWindow("Form1").SwfEdit("Ex_textBox").GetErrorProviderText If Len(ErrorMessage) <> 0 Then SwfWindow("Form1").SwfButton("Cancel").Click Else SwfWindow("Form1").SwfButton("Apply").Click End If
GetItem Method
Description
Returns the value of the item specified by the index.
Syntax
object.GetItem (Index)
Arguments
Parameter | Description |
---|---|
Index |
Required. A Variant. The item name (with quotes) or numeric index (without quotes) can denote the item. The first item in a list-view control is numbered 0. |
Return Type
A String value.
Example
Function SelectListViewItem(expectedItem, ListViewObject) Dim cnt, curItemLabel, curItem 'Select a list item by text 'Return the index of the item found and selected. 'If not found or selection fails, return -1 'Get the number of items in the list cnt = ListViewObject.GetItemsCount 'Iterate through the items For curItem = 0 To cnt - 1 curItemLabel = ListViewObject.GetItem(curItem) itemPath = ListViewObject.GetITemProperty(curItem, "text") 'If found, select If itemPath = expectedItem Then ListViewObject.Select itemPath 'Confirm that selection succeeded ItemSelected = ListViewObject.GetITemProperty(curItem, "selected") If ItemSelected Then SelectListViewItem = curItem Exit Function End If End If Next SelectListViewItem = -1 'Use example: ' Set ListViewObject = SwfWindow("dotNET ListView").SwfListView("listView1") ' expectedItem = "1234567890" '"Year 2007" ' itemIndex = SelectListViewItem(expectedItem, ListViewObject) ' If itemIndex < 0 Then ' reporter.ReportEvent micFail, "Search for item in ListView ", "Item was not found or selected " ' Else ' reporter.ReportEvent micPass, "Search for item in ListView ", "Item found successfully and it's index is " & itemFound ' End If End Function
GetItemProperty Method
Description
Returns the current value of a property for an item in the ListView list.
Syntax
object.GetItemProperty (Item, Property)
Arguments
Parameter | Description | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Item |
Required. A Variant. The item name (with quotes) or numeric index (without quotes) can denote the item. The first item in a list-view control is numbered 0. | ||||||||||||||
Property |
Required. A String value. Property to retrieve from the item in the object's list. See the table below for a list of supported properties. The following properties are supported:
|
Return Type
A Variant.
Example
Function SelectListViewItem(expectedItem, ListViewObject) Dim cnt, curItemLabel, curItem 'Select a list item by text 'Return the index of the item found and selected. 'If not found or selection fails, return -1 'Get the number of items in the list cnt = ListViewObject.GetItemsCount 'Iterate through the items For curItem = 0 To cnt - 1 curItemLabel = ListViewObject.GetItem(curItem) itemPath = ListViewObject.GetITemProperty(curItem, "text") 'If found, select If itemPath = expectedItem Then ListViewObject.Select itemPath 'Confirm that selection succeeded ItemSelected = ListViewObject.GetITemProperty(curItem, "selected") If ItemSelected Then SelectListViewItem = curItem Exit Function End If End If Next SelectListViewItem = -1 'Use example: ' Set ListViewObject = SwfWindow("dotNET ListView").SwfListView("listView1") ' expectedItem = "1234567890" '"Year 2007" ' itemIndex = SelectListViewItem(expectedItem, ListViewObject) ' If itemIndex < 0 Then ' reporter.ReportEvent micFail, "Search for item in ListView ", "Item was not found or selected " ' Else ' reporter.ReportEvent micPass, "Search for item in ListView ", "Item found successfully and it's index is " & itemFound ' End If End Function
Function CustomExtendSelection(arrItems, listObject) ' Select the specified items in a multi-selection list Dim lastItem, curItem, strSelected, idx 'List index is 0-based lastItem = listObject.GetItemsCount - 1 If (arrItems(0) > lastItem Or arrItems(0) < 0) Then CustomExtendSelection = "First requested index out of range" Exit Function End If ' Select the first item listObject.Select arrItems(0) ItemSelected = listObject.GetITemProperty(arrItems(0), "selected") itemText = listObject.GetITemProperty(arrItems(0), "text") If ItemSelected Then strSelected = strSelected & " Selected item -> " & itemText & vbCrLf Else strSelected = _ strSelected & " * Item not selected -> " & itemText & vbCrLf Exit Function End If ' Extend the selection to the other members of the input array For curItem = 1 To UBound(arrItems) idx = arrItems(curItem) If (idx <= lastItem And idx >= 0) Then itemText = listObject.GetITemProperty(idx, "text") listObject.ExtendSelect idx ' Verify selection ItemSelected = _ listObject.GetITemProperty(idx, "selected") If ItemSelected Then strSelected = _ strSelected & " Selected item -> " & itemText & vbCrLf Else 'Selection failed strSelected = _ strSelected & " * Item not selected -> " & itemText & vbCrLf End If Else 'Index out of range strSelected = _ strSelected & CStr(idx) & " out of range" & vbCrLf End If Next CustomExtendSelection = strSelected 'Use example: ' arrForSelect = Array(3, 4, 9, 110) ' Set listObject = _ ' SwfWindow("dotNET ListView").SwfListView("listView1") ' ' Print (CustomExtendSelection(arrForSelect, listObject)) End Function
Function CustomSelectRange(firstItem, lastItem, listObject) Dim cnt, curItem, strSelected 'Select the specified range and verify successful selection If (firstItem < 0) Then firstItem = 0 cnt = listObject.GetItemsCount Last = cnt - 1 ' List is 0-based If (lastItem < Last) Then Last = lastItem ' Select the specified range listObject.SelectRange firstItem, Last ' Check whether each item is selected and output results. For curItem = firstItem To Last ItemSelected = listObject.GetITemProperty(curItem, "selected") itemText = listObject.GetITemProperty(curItem, "text") If ItemSelected Then strSelected = strSelected & " Selected item -> " & itemText & vbCrLf Else strSelected = strSelected & " * Item not selected -> " & itemText & vbCrLf End If Next CustomSelectRange = strSelected 'Use example: ' Set listObject = _ ' SwfWindow("dotNET ListView").SwfListView("listView1") ' ' Select the first nine items ' Print (CustomSelectRange(0, 8, listObject)) End Function
'The following example uses the GetItemProperty method to select different items in the "Form1" window, and then 'retrieve specific properties for each item in the list. SwfWindow("Form1").SwfListView("listBox1").SetItemState "Cyan", micChecked SwfWindow("Form1").SwfListView("listBox1").Select "Green" SwfWindow("Form1").SwfListView("listBox1").SelectRange "Blue" cItems = SwfWindow("Form1").SwfListView("listBox1").GetItemsCount sReport = "SwfListView Item Properties" & vbCr For iItem = 0 To cItems - 1 sReport = sReport & "Item " & iItem & vbTab sReport = sReport & "Selected " & sReport = sReport & "Focused " & SwfWindow("Form1").SwfListView("listBox1").GetITemProperty(iItem, "Focused") & vbTab sReport = sReport & "State " & SwfWindow("Form1").SwfListView("listBox1").GetITemProperty(iItem, "State") & vbTab sReport = sReport & "Selected " & SwfWindow("Form1").SwfListView("listBox1").GetITemProperty(iItem, "Selected") & vbTab sReport = sReport & vbCr Next Reporter.ReportEvent EVENTSTATUS_GENERAL, "SwfListView Item Properties", sReport
GetItemsCount Method
Description
Returns the number of items in the list.
Syntax
object.GetItemsCount
Return Type
A long integer value.
Example
Function SelectListViewItem(expectedItem, ListViewObject) Dim cnt, curItemLabel, curItem 'Select a list item by text 'Return the index of the item found and selected. 'If not found or selection fails, return -1 'Get the number of items in the list cnt = ListViewObject.GetItemsCount 'Iterate through the items For curItem = 0 To cnt - 1 curItemLabel = ListViewObject.GetItem(curItem) itemPath = ListViewObject.GetITemProperty(curItem, "text") 'If found, select If itemPath = expectedItem Then ListViewObject.Select itemPath 'Confirm that selection succeeded ItemSelected = ListViewObject.GetITemProperty(curItem, "selected") If ItemSelected Then SelectListViewItem = curItem Exit Function End If End If Next SelectListViewItem = -1 'Use example: ' Set ListViewObject = SwfWindow("dotNET ListView").SwfListView("listView1") ' expectedItem = "1234567890" '"Year 2007" ' itemIndex = SelectListViewItem(expectedItem, ListViewObject) ' If itemIndex < 0 Then ' reporter.ReportEvent micFail, "Search for item in ListView ", "Item was not found or selected " ' Else ' reporter.ReportEvent micPass, "Search for item in ListView ", "Item found successfully and it's index is " & itemFound ' End If End Function
Function CustomExtendSelection(arrItems, listObject) ' Select the specified items in a multi-selection list Dim lastItem, curItem, strSelected, idx 'List index is 0-based lastItem = listObject.GetItemsCount - 1 If (arrItems(0) > lastItem Or arrItems(0) < 0) Then CustomExtendSelection = "First requested index out of range" Exit Function End If ' Select the first item listObject.Select arrItems(0) ItemSelected = listObject.GetITemProperty(arrItems(0), "selected") itemText = listObject.GetITemProperty(arrItems(0), "text") If ItemSelected Then strSelected = strSelected & " Selected item -> " & itemText & vbCrLf Else strSelected = _ strSelected & " * Item not selected -> " & itemText & vbCrLf Exit Function End If ' Extend the selection to the other members of the input array For curItem = 1 To UBound(arrItems) idx = arrItems(curItem) If (idx <= lastItem And idx >= 0) Then itemText = listObject.GetITemProperty(idx, "text") listObject.ExtendSelect idx ' Verify selection ItemSelected = _ listObject.GetITemProperty(idx, "selected") If ItemSelected Then strSelected = _ strSelected & " Selected item -> " & itemText & vbCrLf Else 'Selection failed strSelected = _ strSelected & " * Item not selected -> " & itemText & vbCrLf End If Else 'Index out of range strSelected = _ strSelected & CStr(idx) & " out of range" & vbCrLf End If Next CustomExtendSelection = strSelected 'Use example: ' arrForSelect = Array(3, 4, 9, 110) ' Set listObject = _ ' SwfWindow("dotNET ListView").SwfListView("listView1") ' ' Print (CustomExtendSelection(arrForSelect, listObject)) End Function
GetSelection Method
Description
Returns all of the selected items in the list.
Syntax
object.GetSelection
Return Type
A String value.
IMPORTANT
The returned string contains all of the selected items in the list separated by line feed characters.
You can use this method only for lists with 1000 or fewer items.
Example
'The following example uses the GetSelection method to return the selected items in the "Names" list. MsgBox SwfWindow("Form1").SwfListView("Names").GetSelection
GetSubItem Method
Description
Returns the text value of a report-style (LVS_REPORT) ListView subitem.
Syntax
object.GetSubItem (Item, [SubItem])
Arguments
Parameter | Description |
---|---|
Item |
Required. A Variant. Name or numeric index of the item. Index values begin with 0. |
SubItem |
Optional. A Variant.
Column name or numeric index of the subitem. Index values begin with 0.
Default value = 0 |
Return Type
A String value.
Example
Function datesOfMarkedItems() 'Get the dates for the selected items in the list ' Specify the column number for Date in report-style mode. date_subitem_number = 1 'Get the indexes of the selected items checkMarks = _ SwfWindow("dotNET ListView").SwfListView("listView1").GetCheckMarks 'Convert the list to an array aCheckMarks = Split(checkMarks, ";") 'Add the label and date of each selected item to the output string For curItem = 0 To UBound(aCheckMarks) curItemNumber = CInt(aCheckMarks(curItem)) itemDate = _ SwfWindow("dotNET ListView").SwfListView("listView1").GetSubItem(curItemNumber, date_subitem_number) curItemLabel = _ SwfWindow("dotNET ListView").SwfListView("listView1").GetItem(curItemNumber) strReturn = _ strReturn & "Item : " & curItemLabel & " date : " & itemDate & vbCrLf Next datesOfMarkedItems = strReturn 'Use example: ' reporter.ReportEvent micDone, _ ' "Retrieved Date for all Items selected items", datesOfMarkedItems End Function
GetTextLocation Method
Description
Checks whether the specified text string is contained in the specified window area.
Syntax
object.GetTextLocation (TextToFind, Left, Top, Right, Bottom, [MatchWholeWordOnly])
Arguments
Parameter | Description |
---|---|
TextToFind |
Required. A String value. The text string you want to locate. |
Left |
Required. A Variant. The left coordinate of the search area within the window or screen, as a long integer. |
Top |
Required. A Variant. The top coordinate of the search area within the window or screen, as a long integer. |
Right |
Required. A Variant. The right coordinate of the search area within the window or screen, as a long integer. |
Bottom |
Required. A Variant. Note: Set the Left, Top, Right, and Bottom coordinates to -1 to search for the text string within the object's entire window. |
MatchWholeWordOnly |
Optional. A Boolean value. If True, the method searches for occurrences that are whole words only and not part of a larger word. If False, the method does not restrict the results to occurrences that are whole words only. Default value = True |
Return Type
A Boolean value.
Indicates whether the text was found in the specified coordinates. Additionally, if the text is found, this method returns the coordinates of the rectangle containing the first instance of the text into the Left, Top, Right, and Bottom arguments.
IMPORTANT
- The text to capture must be visible in the application window when the step runs.
- This method returns True only if the TextToFind argument value is found within a single line in the specified area. The text search restarts on each line of text.
- If the TextToFind argument value includes a space, then this method searches for that text as whole words, regardless of the value set in the MatchWholeWords argument. For example, if you search for "a b" and the text "bla bla" exists, the method will still return False. However, if the MatchWholeWords argument is set to False, then a search for "la" in an area where "bla bla" exists, would return True.
- If the text is found (return value = True) and if the Left, Top, Right, and Bottom arguments are supplied as variables, then the method also returns the exact coordinates of the specified text to the supplied arguments (the returned coordinates overwrite the supplied ones).
- The results of this method may be different depending on the settings selected in the Text Recognition pane of the Options dialog box (Tools menu > Options item > GUI Testing node > Text Recognition node).
- The results of this method may be different in different run sessions depending on the operating system version you are using, service packs you have installed, other installed toolkits, or the APIs used in your application. Therefore, when possible, it is highly recommended to use the GetROProperty Method to retrieve the value of the text (or equivalent) property from an object in your application instead of using the GetTextLocation method.
- By default, when UFT One captures text for a text/text area checkpoint or output value step using the GetText, GetTextLocation, or GetVisibleText methods, it tries to retrieve the text directly from the object using a Windows API-based mechanism. If UFT One cannot capture the text this way (for example, because the text is part of a picture), it tries to capture the text using an OCR (optical character recognition) mechanism. For details about changing this behavior, see the Can QuickTest Professional Text Recognition behavior be modified Knowledgebase article (number KM202721).
Example
'The following example uses the GetTextLocation method to retrieve all of the text within the object. l = -1 t = -1 r = -1 b = -1 result = SwfWindow("Open").SwfEdit("File &name:").GetTextLocation("2002", l, t, r, b) If result Then MsgBox "Text found. Coordinates:" & l & "," & t & "," & r & "," & b End If
GetVisibleText Method
Description
Returns the text from the specified area.
Syntax
object.GetVisibleText ([Left], [Top], [Right], [Bottom])
Arguments
Parameter | Description |
---|---|
Left |
Optional. A long integer value. The left coordinate of the search area within the object's window. Default value = -1 |
Top |
Optional. A long integer value. The top coordinate of the search area the object's window. Default value = -1 |
Right |
Optional. A long integer value. The right coordinate of the search area within the object's window. Default value = -1 |
Bottom |
Optional. A long integer value. The bottom coordinate of the search area a within the object's window. Note: If the Left, Top, Right, and Bottom arguments are not specified, the method returns all of the text within the visible part of the specified object. Default value = -1 |
Return Type
A String value.
IMPORTANT
- The text to capture must be visible in the application window when the step runs.
- The area is defined by pairs of coordinates that designate two diagonally opposite corners of a rectangle.
- The results of this method may be different depending on the settings selected in the Text Recognition pane of the Options dialog box (Tools menu > Options item > GUI Testing tab > Text Recognition node).
- The results of this method may be different in different run sessions depending on the operating system version you are using, service packs you have installed, other installed toolkits, or the APIs used in your application. Therefore, when possible, it is highly recommended to use the GetROProperty Method to retrieve the value of the text (or equivalent) property from an object in your application instead of using the GetVisibleText method.
- By default, when UFT One captures text for a text/text area checkpoint or output value step using the GetText, GetTextLocation, or GetVisibleText methods, it tries to retrieve the text directly from the object using a Windows API-based mechanism. If UFT One cannot capture the text this way (for example, because the text is part of a picture), it tries to capture the text using an OCR (optical character recognition) mechanism. For details about changing this behavior, see the Can QuickTest Professional Text Recognition behavior be modified Knowledgebase article (number KM202721).
Example
'The following example uses the GetVisibleText method to retrieve the text from the "Form1" window. If the returned 'string contains the "login": sub-string, the Type method is used to type the "guest" string in the window. TestText = SwfWindow("Form1").GetVisibleText If InStr(1, TestText, "login:", 1) > 0 Then SwfWindow("Test").Type "guest" End If
'The following example uses the GetVisibleText method to retrieve the text within the specified coordinates. If 'the returned string is not Catalog, the ReportEvent method is used to report a failed step. theText = SwfWindow("Form1").SwfObject("progressBar1").GetVisibleText(16, 25, 56, 92) If theText <> "Catalog" Then Reporter.ReportEvent micFail, "Traders", "Text check failed" End If
MouseMove Method
Description
Moves the mouse pointer to the designated position over the object.
Syntax
object.MouseMove X, Y
Arguments
Parameter | Description |
---|---|
X |
Required. An integer value. The position of the mouse pointer, expressed as x-coordinates (in pixels). Note that the specified coordinates are relative to the upper left corner of the object. |
Y |
Required. An integer value. The position of the mouse pointer, expressed as y-coordinates (in pixels). Note that the specified coordinates are relative to the upper left corner of the object. |
Return Type
None
Example
'The following example uses the MouseMove method to move the mouse pointer to position 10, 5 inside the '"progressBar1" object. SwfWindow("Form1").SwfObject("progressBar1").MouseMove 10, 5
Select Method
Description
Selects an item from the list.
Syntax
object.Select Item, [BUTTON], [Offset]
Arguments
Parameter | Description |
---|---|
Item |
Required. A Variant. The item to select from the list. The item value (with quotes) or numeric index (without quotes) can denote the item. The first item in a list is numbered 0. |
BUTTON |
Optional. A predefined constant or number. The mouse button used to click the object. Default value = micLeftBtn |
Offset |
Optional. An integer value. The horizontal offset (in pixels) of the click location relative to the left margin of the item's text. This argument can be used only if the BUTTON argument is defined. The default value is the center of the object. Default value = -1 |
Return Type
None
Example
Function SelectListViewItem(expectedItem, ListViewObject) Dim cnt, curItemLabel, curItem 'Select a list item by text 'Return the index of the item found and selected. 'If not found or selection fails, return -1 'Get the number of items in the list cnt = ListViewObject.GetItemsCount 'Iterate through the items For curItem = 0 To cnt - 1 curItemLabel = ListViewObject.GetItem(curItem) itemPath = ListViewObject.GetITemProperty(curItem, "text") 'If found, select If itemPath = expectedItem Then ListViewObject.Select itemPath 'Confirm that selection succeeded ItemSelected = ListViewObject.GetITemProperty(curItem, "selected") If ItemSelected Then SelectListViewItem = curItem Exit Function End If End If Next SelectListViewItem = -1 'Use example: ' Set ListViewObject = SwfWindow("dotNET ListView").SwfListView("listView1") ' expectedItem = "1234567890" '"Year 2007" ' itemIndex = SelectListViewItem(expectedItem, ListViewObject) ' If itemIndex < 0 Then ' reporter.ReportEvent micFail, "Search for item in ListView ", "Item was not found or selected " ' Else ' reporter.ReportEvent micPass, "Search for item in ListView ", "Item found successfully and it's index is " & itemFound ' End If End Function
'The following example uses the Select method to select item 2 with the right mouse button, with an offset of '20 pixels. SwfWindow("Form1").SwfListView("listView").Select 2, 1, 20
SelectRange Method
Description
Selects all list items between (and including) two specified items.
Syntax
object.SelectRange Item, [ItemTo]
Arguments
Parameter | Description |
---|---|
Item |
Required. A Variant. One of the items in the range. If the ItemTo argument is not specified, then the Item is one end of the range and the currently selected item is the other end of the range. If the ItemTo argument is specified, then Item is the first item in the range. The item value (with quotes) or numeric index (without quotes) can denote the item. The first item in a list is numbered 0. |
ItemTo |
Optional. A Variant.
The last item of the range.
The item value (with quotes) or numeric index (without quotes) can denote the item. The first item in a list is numbered 0.
|
Return Type
None
IMPORTANT
This method is applicable only to lists that allow multiple selection.
Note: The order of the two items is unimportant. Item can be located above or below ItemTo (or the currently selected item).
Example
Function CustomSelectRange(firstItem, lastItem, listObject) Dim cnt, curItem, strSelected 'Select the specified range and verify successful selection If (firstItem < 0) Then firstItem = 0 cnt = listObject.GetItemsCount Last = cnt - 1 ' List is 0-based If (lastItem < Last) Then Last = lastItem ' Select the specified range listObject.SelectRange firstItem, Last ' Check whether each item is selected and output results. For curItem = firstItem To Last ItemSelected = listObject.GetITemProperty(curItem, "selected") itemText = listObject.GetITemProperty(curItem, "text") If ItemSelected Then strSelected = strSelected & " Selected item -> " & itemText & vbCrLf Else strSelected = strSelected & " * Item not selected -> " & itemText & vbCrLf End If Next CustomSelectRange = strSelected 'Use example: ' Set listObject = _ ' SwfWindow("dotNET ListView").SwfListView("listView1") ' ' Select the first nine items ' Print (CustomSelectRange(0, 8, listObject)) End Function
''The following example uses the SelectRange method to select items 1 through 5 in the "Names" list. SwfWindow("Form1").SwfListView("Names").SelectRange 1, 5
SetItemState Method
Description
Sets the state of the check box for a specified ListView item.
Syntax
object.SetItemState Item, State
Arguments
Parameter | Description |
---|---|
Item |
Required. A Variant. The item whose check box you want to set. The item value (with quotes) or numeric index (without quotes) can denote the item. The first item in a list is numbered 0. |
State |
Required. An integer value. The object's state. The state can either be an index, or one of the following state constants: micChecked (1)--Selects the item's check box.
micUnchecked (0)--Clears the item's check box.
micClick (-1)--Clicks the state icon.
micDblClick (-2)--Double-clicks the state icon.
|
Return Type
None
Example
' Check and uncheck the specified groups of list items ' The input arguments are semi-colon-separated lists of list indexes ' Get the items to be checked into an array aItemsForCheck = Split(ItemsForCheck, ";") ' Check each item For aIndex = 0 To UBound(aItemsForCheck) curItemNumber = CInt(aItemsForCheck(aIndex)) SwfWindow("dotNET ListView").SwfListView("listView1").SetItemState _ curItemNumber, micChecked Next ' Get the items to be unchecked into an array aItemsForUncheck = Split(ItemsForUncheck, ";") ' Uncheck each item For aIndex = 0 To UBound(aItemsForCheck) curItemNumber = CInt(aItemsForCheck(aIndex)) SwfWindow("dotNET ListView").SwfListView("listView1").SetItemState _ curItemNumber, micUnchecked Next ' Use example: SetGroupState "3;8;9", "1;6"
Type Method
Description
Types the specified string in the object.
Syntax
object.Type KeyboardInput
Arguments
Parameter | Description | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
KeyboardInput |
Required. A String value.
The text string and/or constants representing non-alphanumeric keys.
The following constants are available:
|
Return Type
None
IMPORTANT
Although the Type method is supported for most objects, if you enter a Type statement for an object in which a user cannot enter text, the method has no visual effect.
Example
'The following example uses the Type method to press the ENTER (RETURN) key on the button4 button. SwfWindow("Form1").SwfButton("button4").Type micReturn
See also: