C# WebBrowser自动点击弹出提示框

2025-10-08 13:17:32

1、方法一:通过设置Webbrowser的属性来实现

将WebBrowser控件ScriptErrorsSuppressed设置为True即可

C# WebBrowser自动点击弹出提示框

2、方法二:通过控制webbrowser加载后就点击掉,以达到效果

private void webBrowser1_Navigated(object sender, WebBrowserNavigatedEventArgs e) { 

      IHTMLDocument2 vDocument = (IHTMLDocument2)webBrowser1.Document.DomDocument;

      vDocument.parentWindow.execScript("function confirm(str){return true;} ", "javascript"); 

      vDocument.parentWindow.execScript("function alert(str){return true;} ", "javaScript");

}

3、方法三:在页面加载完成后自动关闭,与方法二大体相同

private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e){  

         IHTMLDocument2 vDocument = (IHTMLDocument2)webBrowser1.Document.DomDocument;  

          vDocument.parentWindow.execScript("function confirm(str){return true;} ", "javascript"); 

           vDocument.parentWindow.execScript("function alert(str){return true;} ", "javaScript");

}

声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
猜你喜欢