开发者

Watin Embeded in winform application

开发者 https://www.devze.com 2023-03-06 13:06 出处:网络
I am getting ie script error, how do i handle the dialog in Watin?? i am using the following code, does not work, any suggestions, links, tips.....

I am getting ie script error, how do i handle the dialog in Watin?? i am using the following code, does not work, any suggestions, links, tips..... also tried to disable script debugging, but error is not gone.

-->. how to do it using Watin.

-->. any other method to do the same from the winform application.

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)
开发者_如何学Go{
  //dialog handler to use, but it does not reach here.
}

});

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

Watin Embeded in winform application

Thank you in advance.


Wow, the solution was easer than it looked, before attaching webrowsercontrol to watin, add

webBrowser1.ScriptErrorsSuppressed = true;

sorry guys :)

Thanks any way.


I was having the same problem too, but I didn't want to suppress the dialogs, I wanted to record the errors they were throwing.

The following function should handle this:

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

I have my tests report a "Pass with warnings" result if any script failures end up occurring.

0

精彩评论

暂无评论...
验证码 换一张
取 消