Interacting with alert boxes

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

  return $browser.switchTo().frame(0);
  return $browser.findElement({xpath: '/html/body/button'}).click();

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

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[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: