我正在尝试使用 Selenium Webdriver 处理警报,根据 selenium 文档,正确的实现是:
Alert alert = driver.switchTo().alert();
但是我收到错误消息 The method alert() is undefined for the type WebDriver.TargetLocator
什么版本的 Selenium 2 有这个 web 驱动 api
我正在尝试使用 Selenium Webdriver 处理警报,根据 selenium 文档,正确的实现是:
Alert alert = driver.switchTo().alert();
但是我收到错误消息 The method alert() is undefined for the type WebDriver.TargetLocator
什么版本的 Selenium 2 有这个 web 驱动 api
HmltUnit 驱动程序不支持警报。在 HtmlUnitDriver.java (Selenium 2.0.6) 中:
public Alert alert() {
throw new UnsupportedOperationException("alert()");
}
您使用的是哪个驱动程序?
我正在使用 selenium 2.3,它对我有用。据我所知,警报仅适用于只有确定按钮的窗口。那就是你放 alert.accept(); 的地方 声明。我在警报中看到的另一个问题是它可能会跳过警报,因此您可能必须为该特定警报设置等待语句。希望这可以帮助。
您可能需要为警报使用单独的导入语句:
import org.openqa.selenium.Alert;
我遇到过同样的问题。