To add to gomesr's answer, you might find yourself needing to wait for other elements during your tests. One way to easily have reusable code for this is to use a closure (also known as an anonymous function or a lambda function) to create a spinner function that you can call whenever you're waiting for an element to load.
The spinner function would look like
public function spin ($lambda, $wait = 60) {
for ($i = 0; $i < $wait; $i++) {
try {
if ($lambda($this)) {
return true;
}
} catch (Exception $e) {
// do nothing
}
sleep(1);
}
$backtrace = debug_backtrace();
throw new Exception(
"Timeout thrown by " . $backtrace[1]['class'] . "::" . $backtrace[1]['function'] . "()\n" .
$backtrace[1]['file'] . ", line " . $backtrace[1]['line']
);
}
And to call the function
$this->spin(function($context) {
return ($context->getSession()->getPage()->findById('example')->isVisible());
});
When you call the spinner function you pass an anonymous function with the logic that you want to assert on, in this example it's waiting for an element with an id of 'example' to be visible. The spinner also includes a timeout that will throw an exception if the element is not found within the specified time (default 60 seconds).
The above sample code is from http://docs.behat.org/cookbook/using_spin_functions.html
You can also find more information on spin functions and another code example at http://sauceio.com/index.php/2011/04/how-to-lose-races-and-win-at-selenium/