Forum Discussion

Colin_McCrae's avatar
Colin_McCrae
Community Hero
10 years ago

contentDocument.readyState always "complete" in Chrome?

Hi



I think this has come up before, but I didn't find any workarounds that I liked the look of?



I have a global function I use to wait for pages to load. As you might guess by the thread title, it does this by waiting for the readyState of the page to go to "complete".



It works perfectly with IE, but Chrome (v35) always returns "complete" while it's still loading.



From what I gather, this is a Chrome issue?



Does anyone have any other suggestions to work round this? The two browsers I have to test the site with are Chrome and IE so I'm trying, where possible, to use solutions that will work with both.



The page that's causing me real problems is a search page with a table on it. You do a search, the table contains the results. Problem being, none of the page elements change or are removed while the search happens. So I can't wait until an object appears or vanishes as they are all present, all the time, and only change when it re-renders the page on completion of the search. The browser does indicate that it's loading though and the readyState property of the page updates correctly for IE. But not for Chrome. So searches in Chrome are just a mess as it all gets way too far ahead of itself.



Grrrrrr. I hate Chrome.



(TestComplete v10.20 and I'm using VBScript)

7 Replies

  • Have implemented my solution now and it works great.



    So Chrome uses the "reload" button and IE uses the readyState value.



    It handles if it's the current page refreshing or going from one page to a new one.



    It also handles it if there are multiple browsers open no problem. Whether it's several instances of the same browser or a mixture.



    So far, it seems to work perfectly.



    Of course, it would have been far easier if the readyState property in Chrome worked properly in the first place, but what can you do!
  • I believe I have a solution.



    The "reload" button in the Chrome toolbar can be used.



    While the page is busy, it changes the description text on the button to "Stop loading this page". Once complete, this changes to "Reload this page". Net effect is the same as checking the readyState in IE.



    The project is already cross browser so has the browser in use stored in a global variable. So the wait for page load routine will use this to determine whether to use readyState (IE) or the reload button (Chrome).



    Main thing to be careful of is if you are using multiple browser during the test as you need the BrowserWindow(<num>) object to get to the reload button. But you can either track this yourself or backtrace it using the content of the Address/Search bar to find the parent BrowserWindow you want.



    Either way, it works and I can use it throughout the test(s).



    Happy days. :)
  • TanyaYatskovska's avatar
    TanyaYatskovska
    SmartBear Alumni (Retired)
    Hi Colin,

     


    That's an interesting approach :) Thanks for sharing it!


     


    It's worth saying that TestComplete will recognize Chrome's toolbar buttons only after adding the Chrome_WidgetWin_1 class name to the Open Applications | MSAA project settings.

  • rgratis's avatar
    rgratis
    Frequent Contributor
    Thanks for posting this, Colin.  I've been dealing with browser page load timing issues for months and trying to do things like waiting for page objects, adding delays, etc.  Very time consuming.



    It bears mentioning that I really wish TestComplete would build this functionality into the Page.Wait() method.  That method is basically useless in Chrome at the moment.
  • Any idea if it's possible to monitor the loading spinner that shows in the tab at the page top while it's busy?



    That would do. But I can't see anything relating to it when I look at the tab in the object browser ....
  • Happy to help.



    I suspect the Page.Wait() method falls foul of Chrome always reporting it's state as "complete". It's an annoying bug in the browser. That one little bug makes a simple task like waiting for a page to load very awkward.



    Mind you, with all the sub-page level stuff going on in sites these days, which are detached from the page load status, it's hardly surprising.



    I also do performance testing and we now have an in-house solution for timing sub-page stuff like Ajax events.



    As browsers and sites get more complex, I guess it gets harder and harder for automated solutions to keep up ....
  • rgratis's avatar
    rgratis
    Frequent Contributor
    Yes, for our pages with AJAX, I have to pair the page load monitoring method with another method that tracks our progress spinner... :)



    Tracking the "Reload" button in Chrome seems to be working great based upon yesterday's tests.  I had to work through a few issues with finding the right BrowserWindow object (also wish TestComplete would nest Pages under BrowserWindows...), but I finally got that working as well.