There have been times when changes to AJAX or CSS made my tests fail at times. I added these methods to my static driver instance so that, if necessary, I could check the test for certain conditions. (FROM#)
The TimedWait in the WaitForCssChange method is basically just Threading.Thread.Sleep This is not the most beautiful way, I think, but it works well for my needs.
To wait for Ajax:
public static void WaitForAjax() { var wait = new WebDriverWait(Driver.Instance, TimeSpan.FromSeconds(25)); wait.Until(d => (bool)(d as IJavaScriptExecutor).ExecuteScript("return jQuery.active == 0")); }
For CSS changes:
public static void WaitForCssChange(IWebElement element, string value) { int counter = 0; while (true) { if(element.GetAttribute("style").Contains(value) || counter > 50) { break; } TimedWait(20); counter++; } }
Vdubs
source share