def wait_for_ready_state_complete(driver, timeout=settings.EXTREME_TIMEOUT):
start_ms = time.time() * <NUM_LIT><EOL>stop_ms = start_ms + (timeout * <NUM_LIT>)<EOL>for x in range(int(timeout * <NUM_LIT:10>)):<EOL><INDENT>try:<EOL><INDENT>ready_state = driver.execute_script("<STR_LIT>")<EOL><DEDENT>except WebDriverException:<EOL><INDENT>time.sleep(<NUM_LIT>)<EOL>return True<EOL><DEDENT>if ready_state == u'<STR_LIT>':<EOL><INDENT>time.sleep(<NUM_LIT>)  <EOL>return True<EOL><DEDENT>else:<EOL><INDENT>now_ms = time.time() * <NUM_LIT><EOL>if now_ms >= stop_ms:<EOL><INDENT>break<EOL><DEDENT>time.sleep(<NUM_LIT:0.1>)<EOL><DEDENT><DEDENT>raise Exception(<EOL>"<STR_LIT>" % timeout)<EOL>
The DOM (Document Object Model) has a property called "readyState".
When the value of this becomes "complete", page resources are considered
fully loaded (although AJAX and other loads might still be happening).
This method will wait until document.readyState == "complete".