When trying to check if an alert is present, I call an extension method on IWebDriver
called AlertIsDisplayed
which is this:
try
{
Driver.Instance.SwitchTo().Alert();
return true;
}
catch (NoAlertPresentException)
{
return false;
}
finally
{
Driver.Instance.SwitchTo().DefaultContent();
}
However, due to the fact I am catching an exception, this is quite costly taking 2-3 seconds to return a result. With this being used in hundreds of tests it adds up to several minutes of extra execution time.
So in order to speed it up I tried changing the same method to this:
return ExpectedConditions.AlertIsPresent()(driver) != null;
Where driver
is the IWebDriver
the extension method was called on.
However, this takes the same amount of time. Looking at the source code of ExpectedConditions.AlertIsPresent
reveals why - it is exactly what I was doing before, but just in a wrapper..
I have set my ImplicitWait
to 0.
This is running on Selenium version 2.53.1. My driver is an EventFiringWebDriver
with a WrappedDriver
of FirefoxDriver
. The Firefox version this is running on is 47.0.1.
Are there any alternatives to checking if an alert is present which take less time?