Monday, June 7, 2010

Selenium RC and AJAX

I have been experimenting with Selenium RC and web applications for quite some time now. With WEB 2.0 taking precedence in designing web apps, Automating AJAX is quite an issue for most of the engineers working with Selenium RC.
Here is a quick tip for an AJAX component that I have interacted with.

Auto complete enabled text box, the container that is populated when we start typing in the box is an AJAX component and the selenium select / click commands would fail directly. Here is a simple approach to do this

for (int second = 0;; second++) {
if (second >= 60) fail("timeout");
try
{
if (selenium.isElementPresent("//div[@id='popup-suggestion-menu'/ul/li[1]"))
break;
}
catch (Exception e) {}
Thread.sleep(1000);

}


Here the script is looking for a container named "popup-suggestion-menu" which is displayed when something is typed in the text box. Include this snippet after a selenium.focus and selenium.clickat command on the text box, this is sure to work

Good luck.. I will add more here as I get to know something

No comments:

Post a Comment