Selenium | How to test popup alert message in Selenium Webdriver

|
| By Webner

Below is the script:

package mypackage;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class myclass
{
public static void main(String[] args)
{
WebDriver driver = new FirefoxDriver();
String alertMessage = "";
driver.get("http://demo.webnerserver.com/view/sent_email.php")
driver.findElement(By.cssSelector("input[value="Borrar"]")).click();
alertMessage = driver.switchTo().alert().getText();
driver.switchTo().alert().accept();
System.out.println(alertMessage);
driver.quit();
}
}

See the Screenshot below:

Leave a Reply

Your email address will not be published. Required fields are marked *