Tuesday, July 19, 2011

Selenium and Waiting for Ajax

Keith Sterling posted a post, how to avoid Thread.sleep in automation code in Selenium Smells


Once of the biggest issues I see with people new to Selenium ( or any number of the other web automation tools ) is the liberal scattering of Thread.sleep(xxx) through out the code. This should be considered a bad smell introducing timing specific code into your script.
As this waiting for a element is one of biggest headaches in automation, I thought, I should share my experience.

In Sizzle.js(of jQuery), there is simple code snippet to check if there is an element present

$(window.document).find('locator').length>0

In ajax, the element may be there, but it is may not be visible to the users. So, checking for length alone wont do. For that, checking for visibility will do.

$(window.document).find('locator').is(':visible')
Call these two snippets in the waitforcondition and see the magic. Selenium can automate any ajax or dynamic element actions.

These tricks for only Selenium 1.0. I think, in Se2, these issues may not be there. I need to check and confirm this.

ShareThis

raja's shared items

There was an error in this gadget

My "Testing" Bundle