|
Q:winform中如何实现自动点击webbrowser弹出对话框中的确定按钮
A:
//using mshtml;
//using SHDocVw;
private void Form1_Load(object sender, EventArgs e)
 ...{
this.webBrowser1.Navigate("http://localhost:28512/WebSite2/Default.aspx");
SHDocVw.WebBrowser wb = this.webBrowser1.ActiveXInstance as SHDocVw.WebBrowser;
wb.NavigateComplete2 += new SHDocVw.DWebBrowserEvents2_NavigateComplete2EventHandler(wb_NavigateComplete2);
}

void wb_NavigateComplete2(object pDisp, ref object URL)
 ...{
mshtml.IHTMLDocument2 doc = (this.webBrowser1.ActiveXInstance as SHDocVw.WebBrowser).Document as mshtml.IHTMLDocument2;
doc.parentWindow.execScript("function alert(str){return ''}", "javascript");
}
|