Interacting with alert boxes

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

1 Like

HI @rferreira

Trying to utilize the same option to switch the popup but facing error since the popup can happen at any page. Need your help to fix it.

TaskTimedOut: Task timed-out waiting for element to be located using: By(xpath

https://synthetics.newrelic.com/accounts/1175115/monitors/07def3aa-b660-47be-823c-3cd439b611b9/script?tw[start]=1571064350.324&tw[end]=1571066150.324

Hi @yograj.patel, this looks like the same issue you were having in another post:

I’ve replied there but do let me know if this is a separate issue :slight_smile: