I wrote a stupid wrapper class. This will always output "Timed out on wait" instead of blank text. If you want more specific text, you have to create a wrapper class or a new wait class that applies the function "get_error". I've included my jquery animation wait example at the bottom.
'''
Wrapper for WebDriverWait
'''
from selenium.webdriver.support.ui import WebDriverWait
from selenium.common.exceptions import TimeoutException
class Wait(WebDriverWait):
def __init__(self, driver, timeout):
self.driver = driver
self.timeout = timeout
self.wait = WebDriverWait(driver, timeout)
def until(self, condition):
try:
self.wait.until(condition)
except TimeoutException as exception:
error_func = getattr(condition, "get_error", None)
if callable(error_func):
raise TimeoutException(error_func())
else:
raise TimeoutException("Timed out on wait")
def until_not(self, condition):
try:
self.wait.until_not(condition)
except TimeoutException as exception:
error_func = getattr(condition, "get_error", None)
if callable(error_func):
raise TimeoutException(error_func())
else:
raise TimeoutException("Timed out on wait")
WaitForAnimation class:
'''
Wait for a jquery animation to finish
'''
from selenium.webdriver.support import expected_conditions
class WaitForAnimation(object):
def __init__(self, locator):
self.locator = locator
def __call__(self, driver):
return not driver.execute_script("return jQuery('"+self.locator+"').is(':animated')")
def get_error(self):
return "Timed out waiting for animation of " + self.locator