Micro Focus QTP (UFT) Forums
How to check object existing 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: How to check object existing or not? (/Thread-How-to-check-object-existing-or-not)



How to check object existing or not? - linhke - 01-10-2011

Hi all,

I have this case as:
- Select country that has states, the State drop down is displayed
- Select country that does not have any states, the State drop down is not displayed.
i use the command to check as: rc = Browser("OSS").Page("ManageCustomer").Frame("CustomerDetail").WebList("ddlState").GetROProperty ("disabled").
But the return value of rc is always '0'.
I tried get visible property but the return value is always 'True'.

So i want to ask is there any way to check this case?

Thanks,
linhke


RE: How to check object existing or not? - manishbhalshankar - 01-10-2011

Hi,
This is because the WebList is not disabled if there are no states. Use:
GetROProperty("items count")


RE: How to check object existing or not? - linhke - 01-11-2011

Thanks for your answer,
I have the same with the message, it is a WebElement. When click OK button on the message, it's dismissed but QTP still can get all the property of it with the same value when the message is displayed. So i can not find the way to check it dismissed or not.

Thanks,
linhke


RE: How to check object existing or not? - manishbhalshankar - 01-11-2011

Hi,
You will have to use GetROProperty("items count") on State weblist everytime you change the country. If there are options available in state weblist, items count will be greater than 1 and if there are no states, it will be 0.


RE: How to check object existing or not? - linhke - 01-11-2011

Thank Manish, i know that.
I want to ask the solution to check the message object (it's a WebElement) as i mentioned above.

Many thanks,
linhke


RE: How to check object existing or not? - manishbhalshankar - 01-11-2011

Please provide more details of your message webelement, snapshot and properties..


RE: How to check object existing or not? - linhke - 01-11-2011

The message is the image, and the properties of it are: innertext, outertext, visible, ...
I tried check the property 'Visible', but it is always True during the message is displayed or not.
Thanks,
linhke


RE: How to check object existing or not? - amitspandey - 01-11-2011

Hi,
well u can use the "Exist" property of QTP
Code:
if obj.exist the
msgbox "true"
else
msgbox "false"
end if

hope this helps u.

regards,
Amit
9773539313


RE: How to check object existing or not? - linhke - 01-13-2011

Hi Amit,

I tried your way but the return value is always True, although the Message is not displayed.

Thanks,
linhke


RE: How to check object existing or not? - cdesserich - 01-14-2011

Typically these types of dialog boxes are WebElements using DIV tags. Also, they typically are not actually hidden when not shown, which is why the visible and exist always return true. The trick is that their dimensions are set to 0. If you are able to identify the DIV that represents the dialog box (which it sounds like you have done), you can test the width and height of the WebElement to determine if it is visible or not. Something like:

Code:
If Browser("").Page("").WebElement("").GetROProperty("width") > 0 _
          And Browser("").Page("").WebElement("").GetROProperty("height") > 0 Then
MsgBox "Dialog is visible!"
End If

I use Firebug (with Firefox) to inspect the HTML of the pages I'm testing to determine the DIV structures in situations like this. It's as easy as right-clicking and selecting "Inspect Element." Firebug has really been a great help to me when trying to figure out issues like these. IE has the Developer Toolbar that has similar functionality, but is not as nice. Check them out!