'Polling wait for an arbitrary assertion.'

def wait_for(self, function_with_assertion, timeout=5):

    start_time = time.time()
    while ((time.time() - start_time) < timeout):
        try:
            return function_with_assertion()
        except (AssertionError, WebDriverException):
            time.sleep(0.1)
    return function_with_assertion()
