private static void waitUntilElementReadyStateIsComplete(IHTMLElement element) { //TODO: See if this method could be dropped, it seems to give // more trouble (uninitialized state of elements) // then benefits (I just introduced this method to be on // the save side) if (ElementTag.IsValidElement(element, Image.ElementTags)) { return; } // Wait if the readystate of an element is BETWEEN // Uninitialized and Complete. If it's uninitialized, // it's quite probable that it will never reach Complete. // Like for elements that could not load an image or ico // or some other bits not part of the HTML page. SimpleTimer timeoutTimer = new SimpleTimer(30); do { int readyState = ((IHTMLElement2)element).readyStateValue; if (readyState == 0 || readyState == 4) { return; } Thread.Sleep(Settings.SleepTime); } while (!timeoutTimer.Elapsed); throw new WatiNException("Element didn't reach readystate = complete within 30 seconds: " + element.outerText); }