Micro Focus QTP (UFT) Forums
to check if an item in the list is disabled or not - 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: to check if an item in the list is disabled or not (/Thread-to-check-if-an-item-in-the-list-is-disabled-or-not)



to check if an item in the list is disabled or not - sujaravi123 - 12-12-2011

hi,
there are 4 items in my list box and 2 of them should be disabled.how can i check whether the 2 items are disbaled in the list?

pls help




RE: to check if an item in the list is disabled or not - ravi.gajul - 12-12-2011

you will have to check the property called "disabled" or any other property like"readonly",etc

to do so...use the code as shown below

Code:
strDisabled=Browser().Page().webList().getRoProperty(<get the property using objectsp>)

I have noticed "disabled" holding value "true" if disabled and "false" if enabled.
If you dont see disabled property when you spy the object, you might have to look for other properties like readonly. etc.....if you didn't get this please spy the list item that you wnt to check and post the snap shot of the same.


RE: to check if an item in the list is disabled or not - sujaravi123 - 12-12-2011

But using getroproperty i will get the property of list box as a whole.I need to check whether individual elements in the list box are enabled or disabled


RE: to check if an item in the list is disabled or not - ravi.gajul - 12-12-2011

You may try with below code as reference.
Code:
allItems=split(Browser("title:=Find a Flight.*").Page("title:=Find a Flight.*").WebList("name:=fromPort").GetROProperty("all items"),";")

For i=0 to uBound(allItems)
  
  Browser("title:=Find a Flight.*").Page("title:=Find a Flight.*").WebList("name:=fromPort").Select  allItems(i)
     strVisible=Browser("title:=Find a Flight.*").Page("title:=Find a Flight.*").WebList("name:=fromPort").GetROProperty("visible")
If  strVisible=True Then
msgbox "Enabled" & "   " & allItems(i)
End If
Next

The above code is for the mercury tours sample web application provided by hp.Its a list box for selecting "from" during flight reservation.


RE: to check if an item in the list is disabled or not - sujaravi123 - 12-13-2011

thanks Rahul for this.

But it does not solve my issue SadSad

when we specify the line " strVisible=Browser("title:=Find a Flight.*").Page("title:=Find a Flight.*").WebList("name:=fromPort").GetROProperty("visible")
", it fetches the visible property of the list box as a whole which is true always, i need to fetch the visible property of it's individual elements(whether they are visible or not)


RE: to check if an item in the list is disabled or not - ravi.gajul - 12-13-2011

Code:
Browser("title:=Find a Flight.*").Page("title:=Find a Flight.*").WebList("name:=fromPort").Select  allItems(i)

This obove line will make a selection of an item.There will be few properties based on the selection.So execute the above step and get the property accordingly.If you didn't get it please post the object spy snapshot after selecting the items you want to check for.

Regards,
ravi


RE: to check if an item in the list is disabled or not - PrabhatN - 12-13-2011

Hi Sujaravi,

What happens when you try to select a disabled option? Any other enabled option gets selected? If this is the case you might try Ravi's code as below:

Code:
allItems=split(Browser("title:=Find a Flight.*").Page("title:=Find a Flight.*").WebList("name:=fromPort").GetROProperty("all items"),";")

For i=0 to uBound(allItems)
  
  Browser("title:=Find a Flight.*").Page("title:=Find a Flight.*").WebList("name:=fromPort").Select  allItems(i)
  strSelection=Browser("title:=Find a Flight.*").Page("title:=Find a Flight.*").WebList("name:=fromPort").GetROProperty("selection") //you can also use "value" instead of selection

If  StrComp(strSelection,allItems(i)) = 0 Then
Reporter.ReportEvent micDone,"Status of "&"allItems(i), "Enabled"
Else
Reporter.ReportEvent micDone,"Status of "&"allItems(i), "Disabled"
End If
Next