Created
August 15, 2011 08:51
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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