Handling Alerts in Webpage using Selenium C#
Alerts can be handled by a function called IAlert in C# which helps to accept and dismiss the alerts ( OK and Close/Cancel functions)
You can write a common code as shown below
//Accepting an Alert
public void AlertAccept()
{
IAlert alert = Driver.SwitchTo().Alert();
alert.Accept();
}
//Closing an Alert
public void AlertAccept()
{
IAlert alert = Driver.SwitchTo().Alert();
alert.Dismiss();
}