Forum Discussion

whuang's avatar
whuang
Regular Contributor
5 years ago
Solved

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 level up. Why is that? Is there a way I can get the Link(0) as the direct parent?

Thanks!

  • 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".

3 Replies

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor

    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".

    • whuang's avatar
      whuang
      Regular Contributor

      Thank you, same as you said the find method returns me the link itself. I thought it would give me the child object

  • LinoTadros's avatar
    LinoTadros
    Community Hero

    Great questions!

     

    The className you are seeing is the NOT the Object className, it is the CSS Class Name associated with the object in the browser.

    I know it is a bit confusing, the property should be called "CssClassName" instead of "ClassName"

     

    Cheers

    Lino