Ajax 网页更新后或在框架中 webBrowser 控件找不到 htmlElement
在 winForm 中使用 webBrowser 控件。但是当网页通过 Ajax 或在框架中更新时,我无法使用 webBrowser1.document.getElementById
等来查找 htmlElement
。该元素也不会显示在 IE 中的View->Source code
中。
最终目的是找到 htmlElement
并模拟点击或其他功能,例如 invokeMember("staff")
。
Using webBrowser control in a winForm. but when the webpage is updated by Ajax or in a frame, I cannot usewebBrowser1.document.getElementById
, etc. to find that htmlElement
. The element also won't show in the View->Source code
in IE.
The untimate purpose is to find that htmlElement
and simulate a click or other function likeinvokeMember("staff")
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
WebBrowser 的 Document 对象确实代表了 DOM 的实时视图,因此可能有其他原因导致您无法找到它。然而,DOM 更新不会在 View -> 中表示。来源。您应该使用 IE8 的开发人员工具,它会向您显示 DOM 的实时视图,也许您会看到诸如不正确/重复的 ID 之类的东西。
The WebBrowser's Document object does indeed represent a live view of the DOM so there may be some other reason that you're unable to find it. DOM updates will not however be represented in View -> Source. You should use IE8's developer tools which will show you a live view of the DOM and maybe you'll see something like an incorrect/duplicate ID or something.
我猜您已经自己解决了这个问题,但如果您还没有解决,请参阅我的问题:Web浏览器控件和按 ID 获取元素
本质上,如果您对 WebBrowser 控件执行某些操作(即向 DOM 添加一些成员),它将异步执行此操作。也就是说,它在另一个线程上执行此操作,这样可以避免在 WebBrowser 工作时锁定调用线程。问题是,如果您使用命令以编程方式修改某些内容,则必须等到该命令实际完成加载其更改,然后才能使用它的结果。
检查我的问题以获取我正在做的事情的代码示例。我希望有人能发现我之前的试验有用。
I'm guessing you have already solved this problem on your own, but if you haven't, refer to my question here: WebBrowser Control and GetElement by ID
Essentially, if you do something to the WebBrowser control (ie, add some member to the DOM) it will do so asynchronously. That is, it does it on another thread, that way it avoids locking your calling thread when the WebBrowser is doing work. The problem is that if you programatically modify something with a command, you will have to wait till that command actually finishes loading its changes till you can work with the result of it.
Check my question there for a code example of what I was doing. I hope someone can find my previous trials useful.