winform中如何实现自动点击webbrowser弹出对话框中的确定按钮

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 " );
        }

 

posted on 2007-12-02 22:58  代码王子  阅读(460)  评论(0编辑  收藏  举报

导航