Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
@Test
public void alerts() {
driver.get("https://the-internet.herokuapp.com/javascript_alerts");
driver.findElement(By.xPath("//*[contains(normalize-space(text()), 'Click for JS Alert')]")).click();
driver.switchTo().alert().accept();
driver.findElement(By.xPath("//*[contains(normalize-space(text()), 'Click for JS Prompt')]")).click();
Alert inputAlert = driver.switchTo().alert();
String text = inputAlert.getText();
inputAlert.sendKeys("Look Mom! I can automate alerts :) ");
inputAlert.accept();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment