0

I'm using Selenium in C# and I tried to use the following code to test the presence of a confirm message box (displayed with the javascript function confirm()) and accept it:

IAlert alert = this.Driver.SwitchTo().Alert();
if (alert != null)
{
  alert.Accept();
}

However, this test doesn't work and I get an exception at the first line when the message box doesn't exist

Liam
  • 25,247
  • 27
  • 110
  • 174
Platus
  • 1,417
  • 4
  • 21
  • 43
  • [Please don't put tags in question titles](https://stackoverflow.com/help/tagging) – Liam Jun 07 '17 at 09:40
  • Possible duplicate of [How to check if an alert exists using WebDriver?](https://stackoverflow.com/questions/11467471/how-to-check-if-an-alert-exists-using-webdriver) – Liam Jun 07 '17 at 09:44
  • 1
    the following [C# answer covers it](https://stackoverflow.com/a/30879064/542251) – Liam Jun 07 '17 at 09:45

0 Answers0