Reputation: 57
I'm running the C# tests from remote web driver for an application. I used page refresh after it's redirected to a different application's page to make sure the page exists, but when it refreshes the page, it throws the following error at times:
OpenQA.Selenium.UnhandledAlertException : Unexpected modal dialog (text: To display this page, Firefox must send information that will repeat any action (such as a search or order confirmation) that was performed earlier.): To display this page, Firefox must send information that will repeat any action (such as a search or order confirmation) that was performed earlier.
How can I avoid this in Selenium?
public static void Continue(IWebDriver instance)
{
SeleniumCommand.ClickElementById(instance, "Continue");
instance.Navigate().Refresh();
}
Upvotes: 0
Views: 2810
Reputation: 6551
The UnhandledAlertException
is caused when you try to perform an action, such as a click, when there is an alert box present on the page.
You can dismiss the alert:
instance.SwitchTo().Alert().Dismiss();
Or accept the alert, pending your application:
instance.SwitchTo().Alert().Accept();
Note: Both examples above should be placed only after the alert box displays and before another action is performed.
If the alert is displaying intermittently, you can also wrap the call in a try
/catch
:
try
{
instance.SwitchTo().Alert().Dismiss();
}
catch (NoAlertPresentException)
{
// handle this exception, or just ignore it
}
Upvotes: 3