Internet explorer automation busy v/s readystate property

codeomnitrix picture codeomnitrix · Apr 9, 2012 · Viewed 12.6k times · Source

I am new to vbscript and while reading i found some code as

Do While ie.busy
stateString = stateString & " " & cstr(ie.readystate)
loop
do while ie.readystate <> 4
stateString = stateString & " " & ie.readystate
loop

so could anyone please let me know what is difference between the busy property and readystate property.

Answer

Ekkehard.Horner picture Ekkehard.Horner · Apr 9, 2012

From here:

Michael Harris (MVP) wrote:

        [...]
        do until ie.readyState = 4 : wscript.sleep 10 : loop
        [...]


    Is there a reason to use
      do until ie.readyState = 4 : wscript.sleep 10 : loop
    instead of
      While ie.Busy : WScript.Sleep 10: Wend
    [...]

Just based on past experience in lots of different IE automation scenarios I observed that IE.Busy was not 100% reliable in determining the fully loaded state of the document. It appeared .Busy would oscillate true/false/true/... under some circumstances before the .ReadyState finally arrived at 4 (complete).

That oscillating behavior may have been a bug that is fixed in current versions, but it seems to me more likely that the description of Busy is better than it once was (at least as I recall reading it many years ago). It states simply that IE is busy with navigation or downloading and says nothing explicitly about any connection with the various states the document itself goes through as the DOM is built and page is actually rendered in the browser UI.

The problems avoided by using .ReadyState rather than .Busy are errors thrown in script trying to access/manipulate in incomplete DOM.