'Waits for the script in condition to return True.
Warning: don\'t preface condition with "return"'

def browser_wait_for_js_condition(self, condition, max_wait_time=7, step_time=0.25):

    total_wait_time = 0
    script = ('return    ' + condition)
    while (total_wait_time < max_wait_time):
        time.sleep(step_time)
        total_wait_time += step_time
        if (total_wait_time >= max_wait_time):
            raise KALiteTimeout('Timed    out    waiting    for    js    condition    {0}'.format(condition))
        try:
            if self.browser.execute_script(script):
                break
            else:
                pass
        except WebDriverException:
            pass
