Forum Discussion

whuang's avatar
whuang
Regular Contributor
6 years ago

Why TC skips the direct parent when I use the Parent method?

Hi everyone,   I was trying to use the parent method to get the direct parent of an object, which should be the Link(0) in my screenshot below, but it skipped it and returned me the object one le...
  • tristaanogre's avatar
    6 years ago

    Because contentText may include a variety of objects with the same text.  It's the text version of the content of the HTML tag and all it's children.  So, when you "find" using the content text, it will return the first one found... which is probably the Link itself and not the child panel.  

     

    Also, you are using "Find" twice... basically, telling the code to search for the object... and then search for it again.  A better way would be doing the Find and then assigning the result of the find to a variable and using that for your reference.  Something like

    var myObject

    myObject = Sys.Process('myapp').Find(blah, blah, yada)

    if (myObject.Exists) then

    Log.Message(myObject.Parent.className)

     

    One better... woud be to map your objects using NameMapping and then you wouldn't need to code for the "find".