Tuesday, February 28, 2012

Selenium: simulating click on GWT buttons

In web applications, buttons which are rendered by GWT (google-web-toolkit) cannot be clicked. Selenium RC doesn't recognize them as HTML button. so following will not work for those type of buttons/element

selenium.click(elementLocator)
After some googling, I found out that we can click on these elements by native key events with follwoing code.
 public static void clickOnGWTPopElement(String elementLocator) {
  try{
   //normal click doesn't work on GWT popup elements so we need to perform native mouse operations
   selenium.mouseOver(elementLocator);
   selenium.mouseDown(elementLocator);
   selenium.mouseUp(elementLocator);
  }catch (Exception e) {
   e.printStackTrace(); 
  }  
 }

No comments: