I was talking to someone earlier today who has a very jQuery site; animations, transitions, ajax-y goodness, etc. and realized I had not yet posted this little recipe. jQuery.active is, well, an internal latch that jQuery has that is not part of the official documentation, but that lots of people use. The implementation details are discussed in the first answer of this stackoverflow question (just ignore the warning around the namespace, seems that was reverted)
def wait_for_jquery_active(self):
w = WebDriverWait(self.driver, self.config.getint("Selenium", "timeout"))
w.until(lambda driver : driver.execute_script("return jQuery.active === 0"))
This obviously won’t work if you are just firing html level js events, but if you are waiting on jQuery stuff I’ve had luck with this.
Comments 2
Another good one script for animated widgets (jquery 1.7+) is to filter on animations using this tidbit:
“return $j(‘sizzleSelector’).filter(‘animated’).length === 0;”
It allows the widget to ‘slide out’ before webdriver proceeds to click on a element.
Posted 28 Sep 2012 at 4:35 pm ¶You can use something similar for Dojo (“return dojo.io.XMLHTTPTransport.inFlight.length === 0”) and Prototype (“return Ajax.activeRequestCount === 0”). Originally from http://agilesoftwaretesting.com/selenium-wait-for-ajax-the-right-way/
Posted 01 Oct 2012 at 9:43 am ¶Post a Comment