开发者

HTML Parsing: Clicking element with "onclick" handler does not update WebBrowser ReadyState

I am looking for a way to CLICK an HTML element on a page programmatically. If the page is opened in a Browser and we need to click on a <A> element then instead of clicking we can retrieve the HREF property and Navigate to that url. The benefit of this approach is that the Document::ReadyState returns the correct status, using which we can wait until the page has fully loaded.

The problem comes when the element that needs to be clicked has an onclick handler. Clic开发者_JAVA百科king it does not give any status in ReadyState property or DocumentCompleted event. In this case, how to wait till the document has fully loaded.


Waiting untill the document has loaded is a difficult problem, but you want to continually check for ReadyState and Busy (don't forget that). Also, you can get href of A element, not a problem, but tell me what happens when you click on the A that doesn't trigger the DocComplete or ReadyState, can you give us the outerHTML of this? why isn't it? Is it supposed to be a link that executes a JavaScript function only? If it is following a link, the only way it wont return a DocComplete event is if it returns a NavigateError event. Let us know.

Also, if the page you are waiting for has frames, you need to get a ref to them and check their .busy and .readystate as well, and if the frames are nested, the nested frames .readystate and .busy as well, so you need to write a function that recursively retreives those references.

Now, regarldess of how many frames it has, first fired navigatecomplete event is always the top document, and last fired doccomplete event is always that of the top (parent) document as well.

So you should check to see if its the first call and the pDisp Is WebBrowser1.object (literally thats what you type in yoru if statement) then you know its the navcomplete for top level document, then you wait for this same object in the doc complete, so save the pDisp to a global variable, and wait until a doc complete is run and that Doc Complete's pDisp is equal to the Global pDisp you've saved during the first NavComplete event (as in, the pDisp that you saved globally in the first NavComplete event that fired). So once you know that pDisp was returned in a doc complete, you know the entire document is finished loading.

This will improve your currect method, however, to make it more fool proof, you need to do the frames checking as well, since even if you did all of the above, it's over 90% good but not 100% fool proof, need to do more for this.

Let me know your thoughts and the clarification on my question.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜