Work With List Box

Posted by rajivkumarnandvani on February 5, 2009

When we  use list box Object in QTP. QTP perform following operation on listbox . like

Browser(“Browser”).Page(“Page”)..WebList(“ListBox”).Select “ListBoxValue”

It select the value from List Box that value must be present in list box otherwise QTP give an error  like that

“Cannot identify the specified item of the ListBox object. Confirm that the specified item is included in the object’s item collection.”

So before selection any value in list box Always insure the value you are going to select in list box must be present by use this method/Function

dim objListBox, sValuematch ,bTrue
set objListBox =  Browser(“Browser”).Page(“Page”)..WebList(“ListBox”)
sValuematch =”Type Value that need to be check”
bTrue = fn_Valuematch_for_weblistbx(objListBox  ,sValuematch )
if  bTrue =True then
Browser(“Browser”).Page(“Page”)..WebList(“ListBox”).Select “ListBoxValue”
end if

REM ” this function Check the value u define match With in WEBListbox or Not if match return true otherwise False
Public Function fn_Valuematch_for_weblistbx(byval m_listboxobject, byval m_valuematch)
”check is m_listboxobject  object  or not
If  IsObject(m_listboxobject ) = true and   IsNull(m_valuematch) = false Then
Dim m_Getallfield,m_arAllfield,m_val,m_actual
m_arAllfield = m_listboxobject.GetROProperty(“all items”)
m_arAllfield =Split (m_arAllfield,”;”)
For each element  in  m_arAllfield
If  m_valuematch = element  then ‘ compare the text
fn_Valuematch_for_weblistbx=true ”  if value match then  return true & exit thr loop
exit for
fn_Valuematch_for_weblistbx = false
end if
print  “Error wrong Parameter for function fn_Valuematch_for_listbx”,”Check paramenter value”
End If
End Function


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: