Note that the condition function is called repeatedly until it returns true.
I don't think it is a good idea for such a function to have side effects, such as changing the focus. This should be done before calling `waitFor`.