110,536
社区成员
发帖
与我相关
我的任务
分享
public void OnDocumentComplete(object pDisp, ref object URL)
{
HTMLDocument htmlDocument = (HTMLDocument)browser.Document;
IHTMLElement iframeElement = htmlDocument.getElementById("iframe-id-1");
IHTMLFrameBase2 frameBase2 = (IHTMLFrameBase2)iframeElement;
if (frameBase2.readyState.Equals("complete", StringComparison.OrdinalIgnoreCase))
{
//这一行可以正常弹出提示
//提示内容为: [------Test 1-------] <IFRAME id=iframe-id-1 name=iframe-id-1 src="test.html"></IFRAME>
System.Windows.Forms.MessageBox.Show("[------Test 1-------] " + iframeElement.outerHTML);
//这一行一执行 frameBase2.contentWindow 就已经抛出异常,
//异常信息为:System.InvalidCastException : Specified cast is not valid.
System.Windows.Forms.MessageBox.Show("[------Test 2-------] " + (frameBase2.contentWindow == null ? "yes" : "no"));
}
}
System.InvalidCastException: Specified cast is not valid.
at mshtml.IHTMLFrameBase2.get_contentWindow()