Description
===========
Selenium has methods like shiftKeyDown to control the setting of these keys. Using this works fine in Firefox but fails in Internet Explorer.
Steps to reproduce
==================
1. Download the ZIP File.
2. Import the Java file to your Eclipse
3. Start Selenium Server on port 4444
4. Run the test case (it will do a click without and with shift key pressed - if shift is pressed a text is changed, this is verified)
-> It will do the same test on both Firefox and Internet Explorer, Firefox will pass, IE will fail.
Expected
========
The test case should pass because the second click changes the text.
Actual
======
The test case fails because in Internet Explorer the second click is done without shift.
Solution
======
The error is in selenium-browserbot.js. The function _fireEventOnElement is platform specific. In IEBrowserBot, SafariBrowserBot and KonquerorBrowserBot there is an if clause:
if (element[eventType]) {
element[eventType]();
}
else {
this.browserbot.triggerMouseEvent(element, eventType, true, clientX, clientY);
}
Because element[eventType] is defined it is directly called. In this case the keys are not handled. I changed this condition to:
if (element[eventType] && !this.browserbot.altKeyDown && !this.browserbot.controlKeyDown && !this.browserbot.shiftKeyDown) {
element[eventType]();
} }
else {
this.browserbot.triggerMouseEvent(element, eventType, true, clientX, clientY);
}
This checks if one of the keys Alt, Ctrl or Shift is pressed. In this case it uses the triggerMouseEvent case. For Safari I assume that also the Meta Key has to be checked but as I do not have an Apple here (and also no Konqueror) I am unable to verify this.
Attaching patch for this problem, including test case.
Personally I tested it on IE8, Opera, Google Chrome and FF3.