HTML 解析:使用“onclick”单击元素处理程序不更新 WebBrowser ReadyState

发布于 2024-12-06 16:34:40 字数 293 浏览 1 评论 0原文

我正在寻找一种以编程方式单击页面上的 HTML 元素的方法。如果页面在浏览器中打开,并且我们需要单击 元素,那么我们可以检索 HREF 属性并导航到该 url,而不是单击。这种方法的好处是 Document::ReadyState 返回正确的状态,使用它我们可以等待页面完全加载。

当需要单击的元素具有 onclick 处理程序时,就会出现问题。单击它不会在 ReadyState 属性或 DocumentCompleted 事件中提供任何状态。在这种情况下,如何等待文档完全加载。

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. Clicking it does not give any status in ReadyState property or DocumentCompleted event. In this case, how to wait till the document has fully loaded.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

彼岸花ソ最美的依靠 2024-12-13 16:34:40

等待文档加载是一个难题,但您希望不断检查 ReadyState 和 Busy(不要忘记这一点)。另外,你可以获得A元素的href,这不是问题,但是告诉我当你点击不触发DocComplete或ReadyState的A时会发生什么,你能给我们这个的outerHTML吗?为什么不是呢?它应该是一个仅执行 JavaScript 函数的链接吗?如果它跟随链接,则它不会返回 DocComplete 事件的唯一方法是返回 NavigateError 事件。让我们知道。

另外,如果您正在等待的页面有框架,您需要获取它们的引用并检查它们的 .busy 和 .readystate ,如果框架是嵌套的,则嵌套框架 .readystate 和 .busy 也是如此,所以您需要编写一个函数来递归地检索这些引用。

现在,无论它有多少帧,第一个触发的 navigationcomplete 事件始终是顶部文档,最后一个触发的 doccomplete 事件也始终是顶部(父)文档的事件。

因此,您应该检查它是否是第一次调用,并且 pDisp Is WebBrowser1.object (字面意思就是您在 yoru if 语句中键入的内容),然后您知道它是顶级文档的 navcomplete,然后您等待对于 doc Complete 中的同一对象,因此将 pDisp 保存到全局变量,然后等待 doc Complete 运行并且 Doc Complete 的 pDisp 等于您在第一个过程中保存的全局 pDisp NavComplete 事件(如您在第一个触发的 NavComplete 事件中全局保存的 pDisp)。因此,一旦您知道 pDisp 在文档完成中返回,您就知道整个文档已完成加载。

这将改进您当前的方法,但是,为了使其更加万无一失,您还需要进行帧检查,因为即使您执行了上述所有操作,它也超过 90% 好,但不是 100% 万无一失,需要为此做更多的事情。

让我知道您的想法以及对我的问题的澄清。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文