Forum Discussion

allenj2020's avatar
allenj2020
Contributor
5 years ago

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

  • 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/findchildex-method.html

     

    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.

     

     

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor

    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()
    • allenj2020's avatar
      allenj2020
      Contributor

      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's avatar
        tristaanogre
        Esteemed Contributor

        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/findchildex-method.html

         

        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.