Skip to content

Instantly share code, notes, and snippets.

@rposbo
Created August 15, 2011 08:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rposbo/1145917 to your computer and use it in GitHub Desktop.
Save rposbo/1145917 to your computer and use it in GitHub Desktop.
handy little Selenium helper method to wait for a condition from the server side
/*
Usage:
WaitForCondition(
() => _selenium.GetAttribute(string.Format("//div[@id='{0}']@style", divIdToWatch)).IndexOf("block") >= 0,
5000);
*/
private static void WaitForCondition(Func<bool> condition, int timeoutInMilliseconds)
{
const int wait = 500;
var attempts = timeoutInMilliseconds / wait;
for (var attempt = 0; attempt < attempts; attempt++)
{
if (condition())
break;
Thread.Sleep(wait);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment