If the web page that you testing consists of complex ajax calls, you may be facing the problem where the tests will fail occasionally due to incomplete ajax calls returned.
To deal with this problem, I have added a function in my test:
driver.WaitForAjaxLoadComplete();
And what the function does is:
public static void WaitForAjaxLoadComplete(this IWebDriver driver {
IWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(60.00));
wait.Until(driver1 => (bool)(driver1 as IJavaScriptExecutor).ExecuteScript(“return jQuery.active == 0”));
}
Basically, it tells Selenium to wait until all jQuery calls are completed before the next actions.