我在 WinForms 中有一个 WebBrowser 控件,其 URL 属性设置为外部网页。我还有一个 DocumentCompleted 事件的事件处理程序。在这个处理程序中,我试图获取特定元素,但 wb.Document.Body 似乎在执行 onload 之前捕获了 HTML。
{System.Windows.Forms.HtmlElement}
All: {System.Windows.Forms.HtmlElementCollection}
CanHaveChildren: true
Children: {System.Windows.Forms.HtmlElementCollection}
ClientRectangle: {X = 0 Y = 0 Width = 1200 Height = 0}
Document: {System.Windows.Forms.HtmlDocument}
DomElement: {mshtml.HTMLBodyClass}
ElementShim: {System.Windows.Forms.HtmlElement.HtmlElementShim}
Enabled: true
FirstChild: null
htmlElement: {mshtml.HTMLBodyClass}
Id: null
InnerHtml: "\n"
InnerText: null
Name: ""
NativeHtmlElement: {mshtml.HTMLBodyClass}
NextSibling: null
OffsetParent: null
OffsetRectangle: {X = 0 Y = 0 Width = 1200 Height = 0}
OuterHtml: "<body onload=\"evt_Login_onload(event);\" uitheme=\"Web\">\n</body>"
OuterText: null
Parent: {System.Windows.Forms.HtmlElement}
ScrollLeft: 0
ScrollRectangle: {X = 0 Y = 0 Width = 1200 Height = 0}
ScrollTop: 0
shimManager: {System.Windows.Forms.HtmlShimManager}
ShimManager: {System.Windows.Forms.HtmlShimManager}
Style: null
TabIndex: 0
TagName: "BODY"
"<body onload=\"evt_Login_onload(event);\" uitheme=\"Web\">\n</body>"
是 JavaScript 之前的内容。有没有办法在evt_Login_onload(event);
执行后捕获body标签的状态?
我也尝试过使用wb.Document.GetElementById("id")
,但它返回 null。