def wait_for_ajax_or_reload(browser):
 def _is_ajax_finished():
  ' Wait for jQuery to finish all AJAX calls, if it is present. '
  return browser.execute_script("return typeof(jQuery) == 'undefined' || jQuery.active == 0")
 EmptyPromise(_is_ajax_finished, 'Finished waiting for ajax requests.').fulfill()

def wait_for_ajax_or_reload ( browser ) : def _is_ajax_finished ( ) : return browser . execute_script ( "return typeof(jQuery) == 'undefined' || jQuery.active == 0" ) EmptyPromise ( _is_ajax_finished , 'Finished waiting for ajax requests.' ) . fulfill ( )
wait for all ajax requests to finish .