Your data. Anywhere you go.

New Relic for iOS or Android


Download on the App Store    Android App on Google play


New Relic Insights App for iOS


Download on the App Store


Learn more

Close icon

Interacting with alert boxes

synthetics-script
developer

#1

Here’s an example of using NR Synthetics to interact with and close an alert box.

$browser.get("http://www.w3schools.com/js/tryit.asp?filename=tryjs_alert").then(function(){
  return $browser.switchTo().frame(0);
}).then(function(){
  return $browser.findElement({xpath: '/html/body/button'}).click();
}).then(function(){
    $browser.switchTo().alert().accept();
});

A few important notes:

  • Because of how the w3schools site works, we must first switch to the iframe holding the element we are interesting in clicking on (that’s what the $browser.switchTo().frame(0) is doing)
  • $browser.switchTo().alert() switches the viewport to the alert box and, in this case, all we do is accept it

Related selenium-webdriver documentation http://selenium.googlecode.com/git/docs/api/javascript/class_webdriver_Alert.html


Problems with Pop up Dialog