Forum Discussion
Yes, I totally agree with you, but if it still reports object cannot be found after I told it to wait for the page to load, I really don't know how to fix the issue then. I try not to hardcode a time out if it is not absolutely necessary to avoid unnecessary waiting.
Agreed, hardcoding is not the way to do it. But, obviously, something is going on with the timing. It might be that the "Wait" you have set is still not long enough. The "Wait" method for a page has a parameter that you can set to wait for longer than the default time in your TestComplete settings. It could be that you need to increase that amount to wait longer for the page to load. Again, keep in mind that's a MAXIMUM wait. It won't always wait that amount so, as an experiment, you could make it some astronomically huge number (120000 milliseconds which is 2 minutes) and that will at least see if it fixes the problem. Then you can, at your leisure, tweak it down.
- tristaanogre6 years agoEsteemed Contributor
And, honestly, if it takes longer than 2 minutes for a page to load, even if it's intermittant, I'd write that up as a bug. User experience is key with web apps. I know that if i'm going to a website, I get really ticked off if it takes FOREVER for something to happen if I'm not given some sort of message like "please wait" or "Processing..." or something.
- whuang6 years agoRegular Contributor
My codes call the same action 6 times during the test, and they were all using the same default wait for page time, which is 40 sec. Sometimes only the second call complains object cannot be found, sometimes it is the fourth call, sometimes it could be the second and the third call both not finding the object, but the page was loding no problem, I was monitoring the test while it was running, visually I could see the page was loaded in less than 2 seconds, and the TC progress bar at the top right which display "waiting for page to load" went away after 2 or 3 seconds, so I assumed TC detected the page was loaded completly. So in this case how can I force it to wait longer? I gave it 40 seconds, but it only took a couple seconds and then go to the next line of codes.
- AlexKaras6 years agoChampion Level 3
Hi,
> it still reports object cannot be found after I told it to wait for the page to load
As per documentation, page.Wait() waits for the page to load. I.e. it waits until the last byte for the page request is received from the server. For usual static web pages this is enough.
The bad news is that modern dynamic web pages use a lot of scripting and data obtained from additional resources via additional requests. In the worst case, data load and subsequent rendering is implemented using lazy load technique.
The above means that in addition to wait for the page source to load, you need to wait for all scripts on the page to finish their execution (scripts often drastically change DOM structure of the page) and to wait for all additional data is loaded as well.
Exact algorithm of the wait depends on your tested application.
For example, if you know what element you will work with after page load, you may use this approach:
-- Wait for the page to load;
-- Wait for the element to appear on the page;
-- Optionally, if needed, wait until the element is populated with data;
-- Continue the test.
If you don't know what element you will work with (for example, if you need to delay until complete web page that utilizes lazy loads is loaded), the approach like this should work:
-- Wait for the page to load;
-- Wait for all scripts on the page to finish - this (usually) ensures that all external data is received and rendered;
-- Press Page Down key to scroll page one screen down. This will trigger additional data requests via lazy loads. Repeat the above step to wait until all additional data is loaded;
-- Continue pressing Page Down until some anchor element at the end of the page which is out of page viewport during data load (and thus is not visible on screen) becomes visible on screen;
-- Continue the test.
Related Content
- 11 months ago
- 4 years ago
Recent Discussions
- 2 hours ago
- 20 hours ago