Micro Focus QTP (UFT) Forums
Web List Selection - Printable Version

+- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums)
+-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP)
+--- Forum: VB Scripting/Descriptive Programming (https://www.learnqtp.com/forums/Forum-VB-Scripting-Descriptive-Programming)
+--- Thread: Web List Selection (/Thread-Web-List-Selection)



Web List Selection - mhanaan - 11-23-2012

Given a situation where there is more than one 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 which opens a second window at this point i want the coding to look for a value in the new screen if found then the function is to end with a message box else exit the new window and check the remaining web list item the same way until either the value is found or there are no more items on the list to select.

I am relatively new to QTP and would appreciate help on this issue


RE: Web List Selection - imzeeshan - 11-24-2012

Hi,
In such a case I would go about like this:

Code:
Dim aArray, sArrayItem, nArrayIndex, oBrowserPage, oNewWindow
Set oBrowserPage = Browser("Google").Page("Search")
'Store all items in weblist into an array separated by semi-colon (;)
aArray = oBrowserPage.WebList("lstSampleWebList").GetROProperty("all items")
'Split Weblist items and store in string variable
sArrayItem = Split(aArray,";")
'Run loop until all items have been selected in weblist or exit do statement is executed when value is found
'nArrayIndex=0
Do While nArrayIndex < UBound(aArray)
'Select item in WebList
oBrowserPage.WebList("lstSampleWebList").Select sArrayItem(nArrayIndex)
'Insert code below for the link you want to click after item selection in weblist
oBrowserPage.Link("lnkSampleLink").Click
'New Window opens, set it into an object
oNewWindow = Browser("NewWindow").Page("SearchPage")
'Search your value in the new window
oNewWindow.WebEdit("txtSearchBox").Set sArrayItem(nArrayIndex)   'Value to be searched/looked for. I'm assuming a search box is there.
'Click search button/link
oNewWindow.Link("SearchButton").Click
If oNewWindow.WebEdit("txtValueFound").GetROProperty("text") = sArrayItem(nArrayIndex) Then
'Value found. Show message box and exit Do-While block
msgbox "Value found!"
Exit Do
Else
'Value not found. Close new window and continue loop
oNewWindow.Close
End If
'Increment Array Index so that weblist can select next item.
nArrayIndex = nArrayIndex + 1
End Do

I hope it helps and is understandable.