Forum Discussion

whuang's avatar
whuang
Regular Contributor
5 years ago

Any way to wait for a page fully load the content?

Hi everyone,

 

I am using TestObj.WaitPage(URL, Timeout) to wait for a page and then do the rest on that page, but quite often it complaints the target object cannot be found on the page, but from the screenshot of the error I can see the page was loaded and I could see the target object is available on the page, so I was guessing maybe this WaitPage method just wait for the expected URL to be available and don't care whether the page content fully loaded or not. Is there anyway to wait for the page content fully loaded?

 

Thanks in advance

 

    • whuang's avatar
      whuang
      Regular Contributor

      Is there anyway to wait for page fully loaded? because if I wait for a particular object, it can only apply to that specific test step, but if I can wait for a page fully loaded, then I can use it for all tests.

      • Marsha_R's avatar
        Marsha_R
        Moderator

        Yes, you are using the proper wait function for the page.  I suggest checking the Result value to make sure you are waiting long enough.  

         

        https://support.smartbear.com/testcomplete/docs/reference/test-objects/members/page/wait-action-page-object.html

         

        Result Value

        The Wait method returns the URL of the page or resource that was loaded last on the page. If the web page does not contain frames and the page was loaded successfully, the Wait method returns the page’s URL. If the page contains frames, the method will return the URL of the last page that was loaded in the frame.

        If the loading was not successful or the page was not loaded before the time limit specified by the WaitTime parameter was reached, the method returns an empty string.

  • Hi 
    Give this a try i have done the same it worked for us
    it goes as follows

    1. a is initialized to one

    2. use while loop and check where a is smaller than b(max wait time)

    3. use if condition to check whether the object exists using Exists method

    4. if true break; the statement

    5. increment the value of a with 1

     

    now do the rest

  • AlexKaras's avatar
    AlexKaras
    Champion Level 3

    Hi,

     

    maybe this WaitPage method just wait for the expected URL to be available

    Not exactly.

    From the "WaitPage Method" help topic: "Use this method to pause the script execution until a Page object with the specified URL appears in the object hierarchy or until the specified timeout elapses."

     

    To wait for the given object on web page you must consider the architecture of the tested web page.

    Use <page>.Wait() method to wait until the page source is obtained from the server. Then, unless your page does not use scripting to get additional data and to modify page's DOM, perform explicit wait for the object that you need.

    See, for example, https://community.smartbear.com/t5/TestComplete-General-Discussions/setInterval-is-not-defined-Suggestion-for-best-wait-method/m-p/206198/highlight/true#M38296 thread for more details.

     

  • Mr_Bro's avatar
    Mr_Bro
    Frequent Contributor

    Hi whuang ,

     

    please try using the below and check if this worked for you and let me if this helped you.

    var readyState = page.contentDocument.Script.eval("return document.readyState;");
    if (readyState == TRUE){
       //do something
    }
    or
    if ( page.contentDocument.readyState == True ){
       //do something
    }

     

    Thank You 🙂

     

    • whuang's avatar
      whuang
      Regular Contributor

      Thanks guys for the suggestions above! I will give them a try.

      • sonya_m's avatar
        sonya_m
        SmartBear Alumni (Retired)

        Great job, Community!

         

        whuang did you have a chance to apply the suggestions? If it worked, please mark the best one as a Solution🙂