-1

I know how to handle alerts but when they come unexpectedly then I am not able to handle them and my script failed. When these alert comes, there is no exception and script keeps on running in background without performing any action. I want handle any unexpected alert thrown by application when my script is running.

I will be very thankful if you share your ways to handle an unexpected alert.

Gourav Sinha
  • 203
  • 1
  • 3
  • 12
  • Dont know what exactly u want. You can use webdriverwait – iamsankalp89 Sep 19 '17 at 07:05
  • We all know how to handle alert when it is known where it is coming. If we don't know where alert will come how that can be handled. I want to make a customised exception handler which can deal with any alert during the script. – Gourav Sinha Sep 19 '17 at 07:46
  • Have you looked at this https://stackoverflow.com/questions/26772793/org-openqa-selenium-unhandledalertexception-unexpected-alert-open – HaC Sep 19 '17 at 17:52

1 Answers1

1

you can use

DesiredCapabilities capablity = DesiredCapabilities.internetExplorer();
     capablity .setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR, UnexpectedAlertBehaviour.IGNORE);
     driver = new InternetExplorerDriver(capablity);
iamsankalp89
  • 4,607
  • 2
  • 15
  • 36
  • My script is on IE. Can I use this in IE driver also? – Gourav Sinha Sep 19 '17 at 07:10
  • Ok. @GouravSinha carry on then. If my answer helps you please upvote :) – iamsankalp89 Sep 19 '17 at 07:34
  • We all know how to handle alert when it is known where it is coming. If we don't know where alert will come how that can be handled. I want to make a customised exception handler which can deal with any alert during the script. – Gourav Sinha Sep 19 '17 at 07:37
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/154762/discussion-between-iamsankalp89-and-gourav-sinha). – iamsankalp89 Sep 19 '17 at 07:47