【问题标题】:Watin Embeded in winform application嵌入winform应用程序的Watin
【发布时间】:2011-05-18 08:35:27
【问题描述】:

我收到 ie 脚本错误,我该如何处理 Watin 中的对话框? 我正在使用以下代码,不起作用,任何建议,链接,提示..... 也试过禁用脚本调试,但错误没有消失。

-->。如何使用 Watin 做到这一点。

-->。从 winform 应用程序执行相同操作的任何其他方法。

var __ie = new WebBrowserIE(webBrowser1);

var thread = new Thread(() =>
{
var helper = new DialogHandlerHelper();
using (new UseDialogOnce(__ie.DialogWatcher, helper))
       {
             __ie.GoToNoWait("https://adwords.google.com/o/Targeting/Explorer?__u=1000000000&__c=1000000000&ideaRequestType=KEYWORD_IDEAS#search.none");
System.Threading.Thread.Sleep(5000);
}

foreach (string item in helper.CandidateDialogHandlers)
{
  //dialog handler to use, but it does not reach here.
}

});

thread.SetApartmentState(ApartmentState.STA);
thread.IsBackground = true;
thread.Start();

提前谢谢你。

【问题讨论】:

    标签: c# .net winforms internet-explorer watin


    【解决方案1】:

    哇,解决方案比看起来简单,在将 webbrowsercontrol 附加到 watin 之前,添加

    webBrowser1.ScriptErrorsSuppressed = true;

    对不起各位:)

    谢谢。

    【讨论】:

      【解决方案2】:

      我也遇到了同样的问题,但我不想抑制对话框,我想记录他们抛出的错误。

      下面的函数应该处理这个:

          public static String HandleDialog(IE ie)
          {
              if (ie.HtmlDialogs.Count > 0)
              {
                  HtmlDialog dialog = ie.HtmlDialogs.First();
                  String text = dialog.Text;
                  ie.HtmlDialogs.CloseAll();
                  return text;
              }
              else 
                  return "";
          }
      

      如果最终发生任何脚本故障,我的测试会报告“通过并出现警告”结果。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-07-05
        • 1970-01-01
        • 2011-05-05
        • 2022-01-20
        • 2019-01-06
        相关资源
        最近更新 更多