在使用Java的WebDriver测试中使用driver.switchTo()。alert()时出错

时间:2015-03-23 12:26:36

标签: java selenium selenium-webdriver

driver.findElement(By.xpath("//*[@id='submitButton']")).click();
Alert alert = driver.switchTo().alert();// error message on eclipse  *Type mismatch: cannot convert from org.openqa.selenium.Alert to Alert*
String alertText = alert.getText();// The method getText() is undefined for the type Alert
alert.accept();// The method accept() is undefined for the type Alert
return alertText;

类型提醒未定义driver.switchTo().alert();getText(); accept();方法的错误。

1 个答案:

答案 0 :(得分:0)

您应该导入以下内容:

import org.openqa.selenium.Alert;

上面提到的import语句可以解决问题。