I have written an nUnit test using selenium in c#.
And sometimes an alert may pop up that affects the further passing of tests. I close it with:
try
{
driver.SwitchTo().Alert().Accept();
}
catch (Exception ex)
{
throw new NoAlertPresentException(ex.Message);
}
But if the alert is not found, exceptions are thrown and the test ends, and I need the test to go further, skipping this exception if there is no alert. How can I know when it is active and can be interacted with?
CodePudding user response:
In case all you want is to close the alert if it appears and continue the test flow after that both if alert appeared or not you can simply do nothing in the catch
block. As following:
try
{
driver.SwitchTo().Alert().Accept();
}catch (Exception ex){}