如何使用“UnexpectedAlertBehaviour”处理警报硒的能力? [英] How to handle an Alert with "UnexpectedAlertBehaviour" capability in Selenium?

查看:245
本文介绍了如何使用“UnexpectedAlertBehaviour”处理警报硒的能力?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在selenium framework 2.25中,我看到我们有UnexpectedAlertBehaviour枚举类型,但我不知道如何使用它。

In selenium framework 2.25, I see that we have the UnexpectedAlertBehaviour enum type, but I don't know how to use it.

推荐答案

我在你的问题上找到了这部分文件:
这对其他人也很有用:

I found this portion of documentation on your issue: This may be useful for other people as well:

v2.25.0

=======

WebDriver:

WebDriver:


  • 添加了用于处理BASIC和DIGEST身份验证的API

  • Added API for dealing with BASIC and DIGEST authentication

对话框。目前尚未在任何驱动程序中实现。

dialogs. Currently not implemented in any drivers.

警告用户IE驱动程序将不再使用

Warn users that the IE driver will no longer use the DLL in the

下一个版本。

不推荐使用浏览器的特定WebElement子类。

Deprecated browser specific WebElement subclasses.

已添加支持requiredCapabilities到远程webdrivers

Added support for "requiredCapabilities" to the remote webdrivers

并在firefox

驱动程序中实现对这些驱动程序的基本支持。如果未能满足所需的能力,将导致抛出

driver. Failure to fulfull a required capability will cause a

SessionNotCreatedException。

SessionNotCreatedException to be thrown.

添加了确定未处理的警报应如何处理
的功能。这由unexpectedAlertBehaviour
功能处理,可以是accept,dismiss或
ignore之一。 Java代码应该使用UnexpectedAlertBehaviour
枚举。这仅在Firefox中实现。

允许在Firefox中配置本机事件和

Allow native events to be configured in Firefox and

(实验性)。

将支持的Firefox版本更新为17。

Updated supported versions of Firefox to 17.

.....

提供的整个清单此处

这是来源

package org.openqa.selenium;

    public enum UnexpectedAlertBehaviour {

      ACCEPT ("accept"),
      DISMISS ("dismiss"),
      IGNORE ("ignore")
      ;

      private String text;

      private UnexpectedAlertBehaviour(String text) {
        this.text = text;
      }

      @Override
      public String toString() {
        return String.valueOf(text);
      }

      public static UnexpectedAlertBehaviour fromString(String text) {
        if (text != null) {
          for (UnexpectedAlertBehaviour b : UnexpectedAlertBehaviour.values()) {
            if (text.equalsIgnoreCase(b.text)) {
              return b;
            }
          }
        }
        return null;
      }
    }

我看到你使用unexpectedAlertBehaviour来决定警报是否是未经处理,如果是这样,你将决定如何处理它。

As I see you use unexpectedAlertBehaviour to decide whether alert is unhandled and if it is so, you'll decide how to handle it.

我想它应该是(我的假设):

I suppose it should be something like (my assumption):

try{
alert.accept();
}

catch(org.openqa.selenium.UnexpectedAlertBehaviour){
///...blablabla
}

这篇关于如何使用“UnexpectedAlertBehaviour”处理警报硒的能力?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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