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