我正在编写一个应用程序,它使用 WebBrowser 控件来查看可通过添加新内容/元素的 AJAX 进行更改的 Web 内容。
我似乎无法以我尝试过的任何方式获得新元素。 BrowserCtl.DocumentText 没有最新的页面,当然它也不在“查看源代码”中。
有什么方法可以使用此控件获取这些新数据吗? :(
请帮忙。谢谢!
IE:
Browser.Navigate("www.somewebpagewithAJAX.com");
//Code that waits for browser to finish...
...
//WebBrowser control has loaded content and AJAX has loaded new content
// (is visible at runtime on form) but can't see them in Browser.Document.All
// or Browser.DocumentText :(
我为我解决了这个问题。
关键是,附加一个处理程序onPropertyChanged
通过 ajax 调用填充的 div 元素的事件。
HtmlElement target = webBrowser.Document.GetElementById("div_populated_by_ajax");
if (target != null)
{
target.AttachEventHandler("onpropertychange", handler);
}
最后,
private void handler(Object sender, EventArgs e)
{
HtmlElement div = webBrowser.Document.GetElementById("div_populated_by_ajax");
if (div == null) return;
String contentLoaded = div.InnerHtml; // get the content loaded via ajax
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)