cancel
Showing results for 
Search instead for 
Did you mean: 

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

SOLVED
Highlighted
Frequent Contributor

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?

Capture.JPG

Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Community Hero

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

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


Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available

View solution in original post

3 REPLIES 3
Highlighted
Community Hero

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

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


Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available

View solution in original post

Highlighted
Community Hero

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

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

Highlighted
Frequent Contributor

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

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

New Here?
Join us and watch the welcome video:
Announcements
Top Kudoed Authors