Micro Focus QTP (UFT) Forums
Gathering certain child objects - 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: Gathering certain child objects (/Thread-Gathering-certain-child-objects)



Gathering certain child objects - SBsteven - 11-13-2009

I have narrowed down the code I need to grab only the child objects from the webpage that I want, by using three filters. I just found out that I need to narrow it down a bit more.

I only want the objects that DO NOT have "LCP" in the "innertext".

Here is the code that I am using:

=========================================================

Code:
Dim oDesc 'Description Object
Dim colObject 'Object Collection

Set oDesc = Description.Create
oDesc("micclass").Value = "WebElement"
oDesc("html tag").Value = "SPAN"
oDesc("x").Value = 180
oDesc("text").Value <> "LCP.*"
oDesc("text").regularExpression = True
=======================================================

But it is erroring on this line:
Code:
oDesc("text").Value <> "LCP.*"

I think it doesn't like me using the "<>" to designate NOT EQUAL there. What other syntax can I use?

I can't just use what the innertext does equal because this changes. But I do know that I don't want it to have LCP in the beginning of the object's name.

Thanks!
SBsteven
Also should I be using "text" or "innertext"?

SBsteven


RE: Gathering certain child objects - SBsteven - 11-14-2009

I just found out that I MUST use "innertext" for this.

I ran another test on one of the child objects I did want and it works correctly, but I want to rule certain child objects out.

Here is the line of code I used when I do know the child object's name:

oDesc("innertext").Value = "CSR"

That works fine, but that name can change. I just don't want any child object's that begin with LCP.

SBteven


RE: Gathering certain child objects - SBsteven - 11-14-2009

(Just had some help over at the HP Forums)

Here is the NEW code I am now using:
===========================================

Code:
Dim oDesc 'Description Object
Dim colObject 'Object Collection

Set oDesc = Description.Create
oDesc("micclass").Value = "WebElement"
oDesc("html tag").Value = "SPAN"
oDesc("x").Value = 180
oDesc("innertext").Value = ".*[^LCP]"

Set colObject = Browser("micClass:=Browser").Page("micClass:=Page").ChildObjects( oDesc )

'Retrieve the count
iCount = colObject.Count

msgbox iCount
'Count is now coming back with "2", which is correct

============================================

But now I have another question.

I was just told by a team member to NOT use the x value as a filter, but instead use the instr function.

I could just iterate through the child objects using an index and exclude them if their innertext contains LCP and I could do that with the instr function.

Problem is I don't know much about instr functions. I will do some searching on the web, unless someone here would like to give me a head start on it.

Thanks,
SBsteven