Micro Focus QTP (UFT) Forums
How to prove if an object exists? - 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: UFT / QTP Beginners (https://www.learnqtp.com/forums/Forum-UFT-QTP-Beginners)
+--- Thread: How to prove if an object exists? (/Thread-How-to-prove-if-an-object-exists)



How to prove if an object exists? - lucster - 07-07-2011

Hey guys,

i've had allready two ideas which didn't work yet.
I use QTP 9.2.

My problem:
I want to find at least one object with "innertext:="&Kriterium on a page. So i defined an object and use the following code to prove it. Unfortuneatly the Exist-function doesn't work in this context.

My code first try:
Code:
' define object
Set chKriterium = Description.Create
chKriterium("micclass").Value = "WebElement"
chKriterium("innertext").Value = Kriterium

Browser("P@W Report Viewer").Page("P@W Report Viewer").Frame("Report").ChildObjects(chKriterium).Exist

My code second try:
Code:
' define object
Set chKriterium = Description.Create
chKriterium("micclass").Value = "WebElement"
chKriterium("innertext").Value = Kriterium

Set EditCollection = Browser("P@W Report Viewer").Page("P@W Report Viewer").Frame("Report").ChildObjects(chKriterium)

If  EditCollection.Count > 0 Then
...

Someone can me explain, why it doesn't work and maybe how to solve my problem? Would be great Smile

lucster


RE: How to prove if an object exists? - rajpes - 07-07-2011

If Kriterium is not a variable,you missed quotes on Kriterium

Code:
chKriterium("innertext").Value = "Kriterium"

Otherwise code is fine


RE: How to prove if an object exists? - lucster - 07-07-2011

Thought so as well but QTP throws a "Generall Error" in the "EditCollection"-line.

This line works:
Code:
If  Browser("P@W Report Viewer").Page("P@W Report Viewer").Frame("Report").WebElement("index:=0", "innertext:="&Kriterium).Exist(10) Then
...



RE: How to prove if an object exists? - rajpes - 07-07-2011

in that case it should work with dynamic DP as well if you add another property "index" and that timeout of 10 seconds