
| Key: |
SEL-143
|
| Type: |
New Feature
|
| Status: |
Closed
|
| Resolution: |
Fixed
|
| Priority: |
Minor
|
| Assignee: |
Unassigned
|
| Reporter: |
fjh fekkes
|
| Votes: |
2
|
| Watchers: |
2
|
|
If you were logged in you would be able to see more operations.
|
|
|
|
Issue Links:
|
Relationship
|
|
This issue Relates to:
|
|
SEL-150
fireEvent cannot be used to fire "keyUp" event in Firefox
|
|
|
|
|
|
|
|
Hello,
in a try out of selenium I needed the keyevents and mouseevents to be accessible also.
Therefor I extended the browserbot by the triggerKeyEvent (triggerMouseEvent was already there) and the subsequent functions to make the commands available (Keypress, Keydown, Mouseover and Mousedown). I only defined the commands and browsers (IE and MOZ) I need at the moment, the other events are a straigthforward exercise
Regards,
Fekke
<< htmlutils.js >>
/* FJH Fire a key event in a browser-compatible manner */
function triggerKeyEvent(element, eventType, keycode, canBubble) {
canBubble = (typeof(canBubble) == undefined) ? true : canBubble;
if (element.fireEvent) {
keyEvent = parent.frames['myiframe'].document.createEventObject();
keyEvent.keyCode=keycode;
element.fireEvent('on' + eventType, keyEvent);
}
else {
var evt = document.createEvent('KeyEvents');
evt.initKeyEvent(eventType, true, true, window, false, false, false, false, keycode, keycode);
element.dispatchEvent(evt);
}
}
/* END FJH */
<< selenium-api.js >>
/*
- FJH Key, Mouse event on the located element
*/
Selenium.prototype.doKeypress = function(locator, keycode) {
var element = this.page().findElement(locator);
this.page().keypressElement(element, keycode);
};
Selenium.prototype.doKeydown = function(locator, keycode) {
var element = this.page().findElement(locator);
this.page().keydownElement(element, keycode);
};
Selenium.prototype.doMouseover = function(locator) {
var element = this.page().findElement(locator);
this.page().mouseoverElement(element);
};
Selenium.prototype.doMousedown = function(locator) {
var element = this.page().findElement(locator);
this.page().mousedownElement(element);
};
/* END FJH */
<< selenium-browserbot.js >>
/* FJH Key, Mouse events */
MozillaPageBot.prototype.keypressElement = function(element, keycode) {
triggerEvent(element, 'focus', false);
// Trigger the key event.
triggerKeyEvent(element, 'keypress', keycode, true);
if (this.windowClosed()) {
return;
}
triggerEvent(element, 'blur', false);
};
MozillaPageBot.prototype.keydownElement = function(element, keycode) {
triggerEvent(element, 'focus', false);
// Trigger the key event.
triggerKeyEvent(element, 'keydown', keycode, true);
if (this.windowClosed()) { return; } }
triggerEvent(element, 'blur', false);
};
IEPageBot.prototype.keypressElement = function(element, keycode) {
triggerEvent(element, 'focus', false);
// Trigger the key event.
triggerKeyEvent(element, 'keypress', keycode, true);
if (this.windowClosed()) {
return;
}
triggerEvent(element, 'blur', false);
};
IEPageBot.prototype.keydownElement = function(element, keycode) {
triggerEvent(element, 'focus', false);
// Trigger the key event.
triggerKeyEvent(element, 'keydown', keycode, true);
if (this.windowClosed()) { return; } }
triggerEvent(element, 'blur', false);
};
MozillaPageBot.prototype.mouseoverElement = function(element) {
triggerEvent(element, 'focus', false);
// Trigger the mouse event.
triggerMouseEvent(element, 'mouseover', true);
if (this.windowClosed()) {
return;
}
triggerEvent(element, 'blur', false);
};
MozillaPageBot.prototype.mousedownElement = function(element) {
triggerEvent(element, 'focus', false);
// Trigger the mouse event.
triggerMouseEvent(element, 'mousedown', true);
if (this.windowClosed()) { return; } }
triggerEvent(element, 'blur', false);
};
IEPageBot.prototype.mouseoverElement = function(element) {
triggerEvent(element, 'focus', false);
// Trigger the mouse event.
triggerMouseEvent(element, 'mouseover', true);
if (this.windowClosed()) {
return;
}
triggerEvent(element, 'blur', false);
};
IEPageBot.prototype.mousedownElement = function(element) {
triggerEvent(element, 'focus', false);
// Trigger the mouse event.
triggerMouseEvent(element, 'mousedown', true);
if (this.windowClosed()) { return; } }
triggerEvent(element, 'blur', false);
};
/* END FJH */
|
|
Description
|
Hello,
in a try out of selenium I needed the keyevents and mouseevents to be accessible also.
Therefor I extended the browserbot by the triggerKeyEvent (triggerMouseEvent was already there) and the subsequent functions to make the commands available (Keypress, Keydown, Mouseover and Mousedown). I only defined the commands and browsers (IE and MOZ) I need at the moment, the other events are a straigthforward exercise
Regards,
Fekke
<< htmlutils.js >>
/* FJH Fire a key event in a browser-compatible manner */
function triggerKeyEvent(element, eventType, keycode, canBubble) {
canBubble = (typeof(canBubble) == undefined) ? true : canBubble;
if (element.fireEvent) {
keyEvent = parent.frames['myiframe'].document.createEventObject();
keyEvent.keyCode=keycode;
element.fireEvent('on' + eventType, keyEvent);
}
else {
var evt = document.createEvent('KeyEvents');
evt.initKeyEvent(eventType, true, true, window, false, false, false, false, keycode, keycode);
element.dispatchEvent(evt);
}
}
/* END FJH */
<< selenium-api.js >>
/*
- FJH Key, Mouse event on the located element
*/
Selenium.prototype.doKeypress = function(locator, keycode) {
var element = this.page().findElement(locator);
this.page().keypressElement(element, keycode);
};
Selenium.prototype.doKeydown = function(locator, keycode) {
var element = this.page().findElement(locator);
this.page().keydownElement(element, keycode);
};
Selenium.prototype.doMouseover = function(locator) {
var element = this.page().findElement(locator);
this.page().mouseoverElement(element);
};
Selenium.prototype.doMousedown = function(locator) {
var element = this.page().findElement(locator);
this.page().mousedownElement(element);
};
/* END FJH */
<< selenium-browserbot.js >>
/* FJH Key, Mouse events */
MozillaPageBot.prototype.keypressElement = function(element, keycode) {
triggerEvent(element, 'focus', false);
// Trigger the key event.
triggerKeyEvent(element, 'keypress', keycode, true);
if (this.windowClosed()) {
return;
}
triggerEvent(element, 'blur', false);
};
MozillaPageBot.prototype.keydownElement = function(element, keycode) {
triggerEvent(element, 'focus', false);
// Trigger the key event.
triggerKeyEvent(element, 'keydown', keycode, true);
if (this.windowClosed()) { return; } }
triggerEvent(element, 'blur', false);
};
IEPageBot.prototype.keypressElement = function(element, keycode) {
triggerEvent(element, 'focus', false);
// Trigger the key event.
triggerKeyEvent(element, 'keypress', keycode, true);
if (this.windowClosed()) {
return;
}
triggerEvent(element, 'blur', false);
};
IEPageBot.prototype.keydownElement = function(element, keycode) {
triggerEvent(element, 'focus', false);
// Trigger the key event.
triggerKeyEvent(element, 'keydown', keycode, true);
if (this.windowClosed()) { return; } }
triggerEvent(element, 'blur', false);
};
MozillaPageBot.prototype.mouseoverElement = function(element) {
triggerEvent(element, 'focus', false);
// Trigger the mouse event.
triggerMouseEvent(element, 'mouseover', true);
if (this.windowClosed()) {
return;
}
triggerEvent(element, 'blur', false);
};
MozillaPageBot.prototype.mousedownElement = function(element) {
triggerEvent(element, 'focus', false);
// Trigger the mouse event.
triggerMouseEvent(element, 'mousedown', true);
if (this.windowClosed()) { return; } }
triggerEvent(element, 'blur', false);
};
IEPageBot.prototype.mouseoverElement = function(element) {
triggerEvent(element, 'focus', false);
// Trigger the mouse event.
triggerMouseEvent(element, 'mouseover', true);
if (this.windowClosed()) {
return;
}
triggerEvent(element, 'blur', false);
};
IEPageBot.prototype.mousedownElement = function(element) {
triggerEvent(element, 'focus', false);
// Trigger the mouse event.
triggerMouseEvent(element, 'mousedown', true);
if (this.windowClosed()) { return; } }
triggerEvent(element, 'blur', false);
};
/* END FJH */
|
Show » |
Sort Order:
|
Excellent! Thank you. I needed that too, added methods in local copy but didn't find time to prepare changes to be commited.