You problem is understandable. Because the browser has no clue that there's more stuff to be executed. When a script has finished loading, it doesn't mean that no more work to be done. It could be that a script waits 200 milliseconds and then does something, so there's no generic way of determining when a page has 'fully loaded'.
The DocumentCompleted
event fires when the whole page has been downloaded, and all scripts, images and other dependencies have loaded. So, the DocumentCompleted
does fire at the right time.
However, the captcha seems to be created some time after the document has completed loading, as said, the browser has no clue that he's supposed to wait on this. We can confirm this theory by visiting the page in our browser:
http://minecraft-server.eu/vote/index/2421
When the browser hides the spinning icon (which indicates loading) it takes about 500 more milliseconds for the captcha to actually be visible. You obviously can't rely on 500 milliseconds because it all depends on the connection.
The WebBrowser
component does expose the FileDownload
event, which occurs everytime a file is downloaded. This could be an image that's on the web page, anything. The only problem is that when the event fires, there's no way of know what file the event fired for.
The easiest solution in this case is to check whether the captcha has been loaded, each time the FileDownload
event fires. You should prevent checking for the captcha in the FileDownload
event before the document was completely loaded. So, before iterating over all HTML elements, check whether the document was completely loaded.