#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright 2018 Jorge Javier Araya Navarro
# This file is under the MIT License
# Complete text of the license is at LICENSE
"""Helpers to stop interaction until Kendo UI animations of widgets are done.
"""
from time import sleep
def _runninganim(browser, id_):
return browser.execute_script(
"return jQuery('#%s').is(':animated');" % id_)
[docs]def waitanimation(browser, id_, frequency=0.5, timeout=60):
"""Wait until animation ends or timeout occurs.
Parameters
----------
browser : selenium.webdriver.remote.webdriver.WebDriver
The Selenium web driver containing the HTML
element doing the animation.
id_ : str
The name of the ID of the HTML tag, avoid suffixing it with #.
frequency : float
Time to sleep before checking if the animation
is still running.
timeout : int
Wait time, if exceeded the function will return regardless
of the HTML tag animation state.
Returns
-------
float
Time waited, in seconds.
"""
total = 0.0
inprogress = True
while inprogress and total < timeout:
sleep(frequency)
total += frequency
inprogress = _runninganim(browser, id_)
return total