WebDriverWait Exception only thrown in Debug Mode in Visual Studio 2015 WebDriverWait Exception only thrown in Debug Mode in Visual Studio 2015 selenium selenium

WebDriverWait Exception only thrown in Debug Mode in Visual Studio 2015


I believe this is a quirk of Visual Studio's debug mode. Essentially in debug mode exceptions are sometimes treated as a break even if it is appropriately handled within a try/catch.

Remember when you pass a func to Until() in WebDriver, that func is executed internally within a try. VS is likely hitting the (handled) exception in that method, which is why you do not see it during normal running.

See here for more info.


Here is a workaround, for example if you are trying to find an element:

wait.Until(driver => driver.FindElement(    By.CssSelector(".cssClass")));

You can do this:

wait.Until(driver => driver.FindElements(    By.CssSelector(".cssClass")).FirstOrDefault());

And it will work on both release and debug environments.