Waiting can be hard, so here are a couple of useful tricks to use with jQuery:
First of all, have you ever tried to interact with something on the screen only for some background AJAX call to change what is on the screen at the last possible moment as if it was purposfully trying to break your test? Well lets get rid of that problem by waiting until all AJAX calls have finished processing:
Bear in mind that this will wait until there are no outstanding AJAX calls, once this condition has been met something sneaky could then fire off another AJAX call just to be awkward so it’s not totally foolproof, it should help increase reliability however.
You would use it like this:
WebElement myDropDownMenu = driver.findElement(By.id("menu")); wait.until(listenerIsRegisteredOnElement("mouseover", myDropDownMenu ))
This would make selenium wait until a mouseover listener has been applied to a dropdown menu element (Obviously this example assumes that the menu dropdown is being performed using jQuery).
The above will only work if your site is using jQuery and jQuery is triggering the relevant actions so it is limited, however it is hopefully useful as well, enjoy.