Skip to content

Instantly share code, notes, and snippets.

@ultimate-qa2
Created March 1, 2021 06:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ultimate-qa2/71bfdd00baf734c50350e8c304f45aa9 to your computer and use it in GitHub Desktop.
Save ultimate-qa2/71bfdd00baf734c50350e8c304f45aa9 to your computer and use it in GitHub Desktop.
@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