Ask a Question

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

whuang
Regular Contributor

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

 

10 REPLIES 10
Marsha_R
Community Hero

Try waiting for your particular object instead of the page

https://support.smartbear.com/testcomplete/docs/app-objects/common-tasks/waiting-process-or-window-a...


Marsha_R
[Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
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.

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

 

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.


Marsha_R
[Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
whuang
Regular Contributor

Thank you for the reply. I tried the Wait method and gave it 30 seconds to wait for the page, but it only waited for 4 seconds and then logged the page I asked it to wait for cannot be found. I believe the format I used is correct, Sys.Browser("*").Page("Page_URL").Wait(30000)

For troubleshooting purposes, try a specific browser and a specific page in that line of code and see if it works.


Marsha_R
[Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
abishekhari007
Contributor

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
Community Hero

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-Sugge... thread for more details.

 

Regards,
  /Alex [Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
================================
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
Regular Contributor

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

cancel
Showing results for 
Search instead for 
Did you mean: