C#华廷 - 添加AlertDialogHandler点击每个警报对话框窗口上的确定按钮 [英] C# WatiN - Add an AlertDialogHandler to click ok button on every Alert dialog window

查看:295
本文介绍了C#华廷 - 添加AlertDialogHandler点击每个警报对话框窗口上的确定按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好

那些已经使用谁华廷也有可能使用 DialogHandlers

Those who have used WatiN likely also used DialogHandlers.

那么有人可以教我如何我可以指定一个 DialogHandler中将处理任何警告框的 window.alert() 的,华廷控制下的特定的IE实例。

Well can someone teach me how can i assign a DialogHandler that will handle any Alert Box window.alert(), of a specific IE instance under WatiN control .

DialogHandler中只有在确定按钮,单击非常警报对话框,在这种情况下,我认为我们需要一个 AlertDialogHandler ,基本上只需要单击OK按钮。

The DialogHandler only has to click in the OK button for very alert dialog box, in that case i think we need an AlertDialogHandler that basically only has to click the OK button.

AlertDialogHandler.OKButton.Click()

我已经在网上搜索,发现了几个例子。但他们的时间小周期或您指定的时间工作,我需要一个将永远工作,直到我通过点击一个按钮来阻止它。

I've search the web and found a few examples.. But they work for a small period of time or the time you specify, i need one that will work forever, until i choose to stop it by clicking a button.

这是被窃听我的头几个小时,任何帮助表示赞赏。谢谢

This as been bugging my head for hours, any help is appreciated. Thanks.

注意:有时警告对话框窗口有两个按钮。 。这就是为什么我真的需要单击OK按钮,而不仅仅是关闭对话窗口

Note: Sometimes the alert dialog window has two buttons. Thats why i really need to click the OK button, not just Close the dialog window.

推荐答案

创建类:

public class OKDialogHandler : BaseDialogHandler
{
    public override bool HandleDialog(Window window)
    {
        var button = GetOKButton(window);
        if (button != null)
        {
            button.Click();
            return true;
        }
        else
        {
            return false;
        }
    }

    public override bool CanHandleDialog(Window window)
    {
        return GetOKButton(window) != null;
    }

    private WinButton GetOKButton(Window window)
    {
        var windowButton = new WindowsEnumerator().GetChildWindows(window.Hwnd, w => w.ClassName == "Button" && new WinButton(w.Hwnd).Title == "OK").FirstOrDefault();
        if (windowButton == null)
            return null;
        else
            return new WinButton(windowButton.Hwnd);
    }
}



创建的实例后IE浏览器,重视对话处理它:

ie.AddDialogHandler(new OKDialogHandler());

这对话框处理程序将处理所有的窗口,包含与OK标题的按钮,通过点击该按钮。

This dialog handler will handle all windows, that contains a button with "OK" caption, by clicking on that button.

这篇关于C#华廷 - 添加AlertDialogHandler点击每个警报对话框窗口上的确定按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆