Last active
June 18, 2019 16:12
-
-
Save abelsonlive/b661c3b45af7596f9355 to your computer and use it in GitHub Desktop.
Waiting For responses in selenium
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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