Black Pepper Blog

The thoughts and musings of our team


I've come across an oddity in my functional tests for a GWT application I am working on.

The Selenium RC test I have should simulate a user clicking on a button, implemented as a GWT PushButton (com.google.gwt.user.client.ui.PushButton). The problem is that the click on the button never seemed to work using the following code

 
selenium.click(BUTTON_ID);
 

A GWT PushButton is not a standard HTML <input type="submit" ...> or a <button ...> rather it is a styled button constructed from DIV and other HTML tags.

After some head scratching and experimentation it turns out that the click can be actioned using the following code.

 
selenium.mouseOver(BUTTON_ID);
selenium.mouseDown(BUTTON_ID);
selenium.mouseUp(BUTTON_ID);
 

Not exactly rocket science in the end, but it took a while to work out. Hopefully this will save someone else having to work it out from scratch.


Comments (7)Add Comment
Aaron Novstrup
October 21, 2008
24.22.209.78
Votes: +2
...

This workaround worked for me with GWT 1.4.61, but it broke in IE when I upgraded to GWT 1.5.2. Know of any other workaround, short of invoking the event handler directly through javascript?

John Eccleston
October 24, 2008
81.141.66.56
Votes: -1
...

Hi Aaron,

thanks for the feedback. I tested this with GWT 1.5.2 on Firefox. I'll have a play with IE, and also with GWT 1.5.3

Thibaut
November 03, 2008
194.78.35.170
Votes: +1
...

Hello, I made some experiments.

IE6 and GWT 1.4.? : The 'mouseOver/mouseDown/mouseUp' method works perfectly.

IE7 and GWT 1.5.3 : The 'mouseOver/mouseDown/mouseUp' method does NOT work at all. But it will work again with this:

selenium.focus(pLocator);
selenium.keyPress(pLocator, "r");

Hope this can help.

pio
April 24, 2009
91.150.223.18
Votes: +0
...

Hello,
I didn't use it in GWT 1.5.3 but I have problem in GWT 1.6. with clicking CustomButton (for example PushButton).
Neither 'mouseOver/mouseDown/mouseUp' nor 'focus/heyPress' method work in IE7

Do you have any workaround for it?

VladS
November 12, 2009
99.226.157.179
Votes: -1
...

protected void click(String locator) {
if (locator.endsWith("PushButton")) {
// Special case for cool buttons
if (isTargetFirefox()) {
// Work OK in FF 3.5.
String imageLocator = "//div[@id='" + locator + "']/img";
selenium.mouseOver(imageLocator);
selenium.mouseDown(imageLocator);
selenium.mouseUp(imageLocator);
} else {
// Work OK in IE7
String imageLocator = "//div[@id='" + locator + "'][1][1]";
selenium.focus(imageLocator);
selenium.keyPressNative(Integer.toString(KeyEvent.VK_SPACE));
}
} else {
selenium.click(locator);
}
}

Aarti
January 07, 2010
80.169.134.210
Votes: +0
...

Try this :-
selenium.FireEvent(locator, "click");
E.g. :-
selenium.FireEvent("css=input[name='buy']", "click");
This should work for sure. Please try and let me know

moon
January 08, 2010
208.100.40.34
Votes: +0
...

selenium.FireEvent(locator, "click");

its not working in IE7 n IE8.... :( :( :(

any other workarounds????

Write comment
 
  smaller | bigger
 

security image
Write the displayed characters


busy