Skip to content

Instantly share code, notes, and snippets.

@abelsonlive
Last active June 18, 2019 16:12
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abelsonlive/b661c3b45af7596f9355 to your computer and use it in GitHub Desktop.
Save abelsonlive/b661c3b45af7596f9355 to your computer and use it in GitHub Desktop.
Waiting For responses in selenium
from selenium import webdriver
from selenium.webdriver.support.wait import WebDriverWait
class WaitBrowser(object):
def __init__(self, **kw):
self.browser = webdriver.PhantomJS()
def readystate_complete(self):
# AFAICT Selenium offers no better way to wait for the document to be loaded,
# if one is in ignorance of its contents.
return self.browser.execute_script("return document.readyState") == "complete"
def wait(self, timeout=30):
WebDriverWait(self.browser, timeout).until(self.readystate_complete)
wb = WaitBrowser()
wb.browser.get('http://example.com')
wb.wait()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment