QTP Code to Select All items from a list box

The following QTP code can be used in case we want to select multiple values in a list box. Here, I have selected all the items.

   1: Set oPage=Browser("Browser").Page("Page Name")
   2: Set Lists=WebListObjects(oPage)
   3: AllDataItems=Lists(3).GetROProperty("items Count")
   4: 'select all the data items
   5: For i=2 to AllDataItems
   6:    x=Lists(3).GetItem(i) 
   7:    Lists(3).ExtendSelect  x
   8: Next

Explanation:-

1.set the current page
2. Set the List object by calling function. To view the WebListObjects is a function which is defined. Click here to view the function
3. Store the number of records in required list, in the variable AllDataItems
5. Initiate the for loop to traverse through the data items in the list
6. Store each item of list into a variable x
7. Select the elements one by one

This Post Has 3 Comments

  1. Unknown

    given a situation where there are three or more items in the web list i want qtp to select each item one by one and perform an action in my case to select the the item then click on a link at this point i want the coding to look for a value if found then ok else it needs to loop with every item on the list until either the value is found or there are no more items on the list to selec

  2. Amita

    Hi Hanaan,
    Try following
    'select all the data items
    Set data = "xyz"

    For i=2 to AllDataItems

    x=Lists(3).GetItem(i)
    if(x = data)
    Lists(3).ExtendSelect x

    Next

  3. Anonymous

    already i know which value to select.so set in the object.But the has an integer value.
    how to select the specific number in the list through the select
    It tried with
    set bday=20
    Browser(brs).Page(pg).Weblist("").Select(bday)

Comments are closed.