华廷捕获弹出窗口,然后按一下,YES接 [英] watin capture popup window and click "Yes"

查看:151
本文介绍了华廷捕获弹出窗口,然后按一下,YES接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用华廷登录到一个网站,检索信息。如果有另一个已登录为同一帐户存在于其他地方,该网站弹出一个窗口,说:关闭其他会话?和有两个按钮是和否。我需要抓住这一点,并单击是。

我不知道是什么类型的弹出的是,我试图AlertDialogHandler和ConfirmDialogHandler,但似乎没有工作,任何人都可以帮助?下面是code sniplet。谢谢!

  BrowserIe.Ie.Image(Find.ByName(登录))ClickNoWait()。

    AlertDialogHandler D =新AlertDialogHandler();
    如果(d.Exists())
    {
        log.Debug(得到......在登录时提示对话框);
        d.OKButton.Click();
    }

    ConfirmDialogHandler确认=新ConfirmDialogHandler();
    如果(confirm.Exists())
    {
        {
            log.Debug(得到确认对话框中......登录时);
           confirm.OKButton.Click();
        }

    }
 

解决方案

这应该工作:

  ConfirmDialogHandler确认=新ConfirmDialogHandler();
使用(新UseDialogOnce(BrowserIe.DialogWatcher,确认))
{
    BrowserIe.Image(Find.ByName(登录))ClickNoWait()。
    confirm.WaitUntilExists();
    confirm.OKButton.Click();
}
 

根据消息的速度,你甚至可能不会需要等待的方法。

另一种方式对皮肤同样的猫是覆盖JavaScript的confirm函数,返回true:

  BrowserIe.RunScript(功能确认(消息){返回true;});
 

I use watin to log into a website and retrieve information. If there is another login already exist for the same account in somewhere else, the website popup a window and say "close other sessions?" and there are two buttons "Yes" and "No". I need to capture this and click "Yes".

I don't know what type of the popup is, I tried AlertDialogHandler and ConfirmDialogHandler, but seems not working, could anyone help?? below is the code sniplet. Thanks!

   BrowserIe.Ie.Image(Find.ByName("login")).ClickNoWait();

    AlertDialogHandler d= new AlertDialogHandler();
    if(d.Exists())
    {
        log.Debug("got alert dialog when logging in...");
        d.OKButton.Click();
    }

    ConfirmDialogHandler confirm = new ConfirmDialogHandler();
    if(confirm.Exists())
    {
        {
            log.Debug("got confirm dialog when logging in...");
           confirm.OKButton.Click();
        }

    }

解决方案

This should work:

ConfirmDialogHandler confirm = new ConfirmDialogHandler();
using (new UseDialogOnce(BrowserIe.DialogWatcher, confirm))
{
    BrowserIe.Image(Find.ByName("login")).ClickNoWait();
    confirm.WaitUntilExists();
    confirm.OKButton.Click();
}

Depending on the speed of the message, you may not even need the Wait method.

Another way to skin this same cat is to override the JavaScript confirm function, returning true:

BrowserIe.RunScript("function confirm(message) { return true; }");

这篇关于华廷捕获弹出窗口,然后按一下,YES接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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