More

    UFT Function to Select an item from a WebList or WinComboBox

    UFT/QTP Function to select an item form WebList or WinComboBox. This function is capable of selecting a list item specified in the function call and report pass or fail based on the result. To create and test this function, we have made use of the sample WebList given below and WinComboBox from HP QTP Flight Application.

    Sample WebList
    Select a destination:

    Function Overview

    Function Overview
    Function NameSelectItemFromList (ByVal TestObject, ByVal ListItem)
    Function DescriptionFunction to Select an item from a WebList or WinComboBox
    Data ParametersTestObject:- Specify the WebList or WinComboBox.
    ListItem:- Specify the list item to be selected from the WebList.

    The Function

    '--------------------------------------------------------------------------------------------------------------------------------------------
    'Function Name        : SelectItemFromList (ByVal TestObject, ByVal ListItem)
    'Function Description : Function to Select an item from a WebList or WinComboBox
    'Data Parameters      : TestObject:- Specify the WebList or WinComboBox. eg for WebList: Browser("-----").Page("-----").WebList("-----")
    '                       eg for WinComboBox:  Window("-----").WinComboBox("-----")
    '                       ListItem:- Specify the list item to be selected from the WebList. eg: "Cruises"
    '--------------------------------------------------------------------------------------------------------------------------------------------
    Function SelectItemFromList (ByVal TestObject, ByVal ListItem)
     Rem: to handle any unexpected error
     On Error Resume Next
     MatchFound = FALSE
     SelectItemFromList = FALSE
     ValidObject = FALSE
     Rem: checking whether the TestObject in the AUT
     ObjectExist = TestObject.Exist(10)
     If ObjectExist Then
      Rem: finding the TestObject class
      Select Case TestObject.GetROProperty("micclass")
       Case "WebList"
        Rem: getting the number of items present in the TestObject
        ListItemsCount = TestObject.GetROProperty("items count")
        ListStart = 1
        ListEnd = ListItemsCount
        ValidObject = TRUE
       Case "WinComboBox"
        Rem: getting the number of items present in the TestObject
        ListItemsCount = TestObject.GetROProperty("items count")
        ListStart = 0
        ListEnd = ListItemsCount - 1
        ValidObject = TRUE
       Case Else
        Rem: reporting error in case the TestObject specified in function call is not WebList or WinComboBox
        Reporter.ReportEvent micFail, "Object Error", "Object '" & TestObject.ToString & "' specified in function call is not a WebList or WinComboBox."
      End Select
      If ValidObject Then
       For iList = ListStart to ListEnd
        CurrentListItem = TestObject.GetItem(iList)
        If StrComp(Trim(CurrentListItem), Trim(ListItem), vbTextCompare) = 0 Then
         MatchFound = TRUE
         TestObject.Select CurrentListItem
         Item_Selected = TestObject.CheckProperty("selection", CurrentListItem, 1000)
         Exit For
        End If
       Next                
       If MatchFound And Item_Selected Then
        SelectItemFromList = TRUE
        Reporter.ReportEvent micPass, "Specified List item selected.", "Specified item '" & ListItem & "' was selected from '" & TestObject.ToString & "'."
       ElseIf Not MatchFound Then
        Reporter.ReportEvent micFail, "List item selection failed.", "Specified item '" & ListItem & "' was not selected from '" & TestObject.ToString & "'."
       End If
      End If
     ElseIf Not ObjectExist Then
      Rem: reporting error if TestObject is not found in AUT
      Reporter.ReportEvent micFail, "Cannot Find The Object", "Object specified in function call cannot be found."
     End If
    End Function

    Function Usage

    Using Function for Web List

    Rem: Using function for WebList
    
    Call SelectItemFromList(WebListTestObject, "-Select-")
    Rem: Result:- Specified item '-Select-' was selected from '[ select ] list'.
    
    Call SelectItemFromList(WebListTestObject, "Dublin")
    Rem: Result:- Specified item 'Dublin' was selected from '[ select ] list'.
    
    Call SelectItemFromList(WebListTestObject, "Dublins")
    Rem: Result:- Specified item 'Dublins' was not selected from '[ select ] list'.
    
    Call SelectItemFromList(InvalidWebListTestObject, "Dublin")
    Rem: Result:- Object '[ Aneejian] Web page' specified in function call is not a WebList or WinComboBox.

    Using Function for WinComboBox

    Rem: Using Function for WinComboBox
    
    Call SelectItemFromList(WinComboBoxTestObject, "Zurich")
    Rem: Result:- Specified item 'Zurich' was selected from '[ Fly From: ] list'.
    
    Call SelectItemFromList(WinComboBoxTestObject, "Denver")
    Rem: Result:- Specified item 'Denver' was selected from '[ Fly From: ] list'.
    
    Call SelectItemFromList(WinComboBoxTestObject, "Zuricsh")
    Rem: Result:- Specified item 'Zuricsh' was not selected from '[ Fly From: ] list'.
    
    Call SelectItemFromList(InvalidWinComboBoxTestObject, "Zurich")
    Rem: Result:- Object '[ Button ] button' specified in function call is not a WebList or WinComboBox.

    Related Articles

    Recent Articles

    How to fix Date Time data type issue in Blue Prism?

    Know more about the date time issue while using the code stage in Blue Prism and understand how to fix it by dealing with the UTC offset.

    How to deserialize JSON in UiPath?

    Tutorial on how to properly deserialize JSON with UiPath Web Activities. Explains the concept of JSON Array and JSON Object.

    Dynamic or Variable Selectors in UiPath

    Tutorial on how to use dynamic selectors in UiPath. Explains how to use variables in UiPath selectors.

    Change Case Excel Add-In

    Change Case Excel Add-In is a powerful Excel Add-In that can change the case of selected cells. With easy to use Keyboard shortcuts, perform case conversion in style.

    Blue Prism Video Tutorial

    A well-structured video tutorial on Blue Prism, which is the right starting point for your RPA career. #rpa #blueprism

    Leave a Reply

    This site uses Akismet to reduce spam. Learn how your comment data is processed.

    Stay on top - Get latest articles in your inbox