Ask a Question

FindChild for newly created page objects

SOLVED
allenj2020
Contributor

FindChild for newly created page objects

Hello all,

 

I'm a long time TestComplete desktop user, just getting used to the web object handling.

What I'm trying to figure out is how to consistently handle a situation where I click on a button on a page, and it causes a popup dialog (new page), that I want to perform operations on.

That page has objectIdentifiers, so I can use FindChild to find and operate on them, which is good because the object path can be quite deep.  But, they may not be rendered yet so FindChild doesn't find the object.

What's the best way to do a dynamic wait to see if the new page is fully loaded before I search for an object in it?

I am not using NameMapping.

 

I tried this syntax, but it doesn't work consistently, the first WaitPanel often returns before I can find the child.

Sys.Browser("chrome").Page("*").WaitPanel(1, 5000);  // This returns immediately without waiting

Sys.Browser("chrome").Page("*").FindChild("contentText", "Available Locations*");

 

Thanks.

Allen

1 ACCEPTED SOLUTION

Accepted Solutions
tristaanogre
Community Hero

Re: FindChild for newly created page objects

Well, you're calling "WaitPanel" from the page object.  So, it's waiting for the immediate Panel(1) right off the page object.  This is why it's returning immediately because I'm assuming that there is already a Panel(1) on the main page that you didn't need to wait for.

 

FindChild, as you're using it, doesn't have a Timeout/Wait built into it.  To do that, you should use FindChildEx

 

https://support.smartbear.com/testcomplete/docs/reference/test-objects/members/common-for-all/findch...

 

This will search for the child but note that you will need to specify a depth to search.  Again, as you have it set, it's only searching the immediate child of the page so that's why  it's not working well.

 

Side note: Some of this WOULD be a bit simpler if you utilized Aliases of mapped objects.  You could map the desired panel, make it a direct Alias child of the page, and then use page.WaitAliasChild("childName", 5000) to wait for the object.

 

 


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

6 REPLIES 6
tristaanogre
Community Hero

Re: FindChild for newly created page objects

There is a Wait method inherent in any page object.  So, once you perform an action, if you want to wait for a page to load or reload, call that method so... something like

 

Aliases.browser.myPage.someButton.click();
Aliases.browser.myOtherPage.Wait()
Aliases.browser.myOtherPage.aDifferentbutton.click()

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
allenj2020
Contributor

Re: FindChild for newly created page objects

I'm not waiting for a new page, the URL doesn't change, I'm waiting for a new object to appear on the same page.

 

So, in the simplest case, I'm working with mypage.Panel(0) in the object tree.

I click a button, the URL remains the same, but now mypage.Panel(1) is created, it didn't exist in the object tree before.

I need to find an object inside Panel(1).

 

Wait only applies to the page object, not a child panel. 

WaitPanel seemed like the way to go, I saw the technique in an old forum post, but it doesn't wait, or at least it doesn't wait long enough.

 

Thanks.

Allen

 

tristaanogre
Community Hero

Re: FindChild for newly created page objects

Well, you're calling "WaitPanel" from the page object.  So, it's waiting for the immediate Panel(1) right off the page object.  This is why it's returning immediately because I'm assuming that there is already a Panel(1) on the main page that you didn't need to wait for.

 

FindChild, as you're using it, doesn't have a Timeout/Wait built into it.  To do that, you should use FindChildEx

 

https://support.smartbear.com/testcomplete/docs/reference/test-objects/members/common-for-all/findch...

 

This will search for the child but note that you will need to specify a depth to search.  Again, as you have it set, it's only searching the immediate child of the page so that's why  it's not working well.

 

Side note: Some of this WOULD be a bit simpler if you utilized Aliases of mapped objects.  You could map the desired panel, make it a direct Alias child of the page, and then use page.WaitAliasChild("childName", 5000) to wait for the object.

 

 


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

tristaanogre
Community Hero

Re: FindChild for newly created page objects

Additional note: If you're going to use "FindChildEx", after the find is executed, do an "Exists" check of the resulting object that the method returns before you attempt to use it.  


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
allenj2020
Contributor

Re: FindChild for newly created page objects

FindChildEx does do the trick, thanks.  I was not familiar with the power of that command.

 

For the record, no, at least according to the object tree Panel(1) (which is a top level object) does not exist until I click the button inside Panel(0).  The power of React, I guess.  But I'm not sure why FindPanel doesn't work consistently in that situation, I'm guessing it finds the object as soon as it's created before the new object tree is fully rendered?

 

Anyway, I'll work with FindChildEx for a while and see how it goes.

 

Thanks!

Allen

 

tristaanogre
Community Hero

Re: FindChild for newly created page objects

Well, Panel(1) that is further down the hierarchy tree probably doesn't exist until the button is clicked, but that doesn't preclude other Panel objects higher up the hierarchy from existing.  You could have something like this.

 

Browser|

               - Page |

                            - Panel(0) |

                                             - Panel(0)  <- The panel zero you're clicking on

                                             - Panel(1)  <- The panel one that doesn't exist until you click

                            - Panel(1) <- The panel one that is present as a direct child of the page

                           

This structure would generate the behavior you're experiencing.  Web applications have a LOT of panels and divs and such so buttons and other objects are NOT necessarily the direct child of the page but may be many layers deep.  Since you're coming over from Desktop applications, this is a rather big difference between how the applications show up in the object browser and requires different techniques for finding and identifying objects.

 


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
cancel
Showing results for 
Search instead for 
Did you mean: