Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.