1

我正在尝试使用 Selenium Webdriver 处理警报,根据 selenium 文档,正确的实现是:

Alert alert = driver.switchTo().alert();

但是我收到错误消息 The method alert() is undefined for the type WebDriver.TargetLocator

什么版本的 Selenium 2 有这个 web 驱动 api

4

3 回答 3

1

HmltUnit 驱动程序不支持警报。在 HtmlUnitDriver.java (Selenium 2.0.6) 中:

public Alert alert() {
  throw new UnsupportedOperationException("alert()");
}

您使用的是哪个驱动程序?

于 2011-09-20T08:41:00.057 回答
0

我正在使用 selenium 2.3,它对我有用。据我所知,警报仅适用于只有确定按钮的窗口。那就是你放 alert.accept(); 的地方 声明。我在警报中看到的另一个问题是它可能会跳过警报,因此您可能必须为该特定警报设置等待语句。希望这可以帮助。

于 2011-08-30T13:55:46.237 回答
0

您可能需要为警报使用单独的导入语句:

import org.openqa.selenium.Alert;

我遇到过同样的问题。

于 2011-09-22T17:17:32.937 回答