diff --git a/javascript/firefox-driver/js/syntheticMouse.js b/javascript/firefox-driver/js/syntheticMouse.js index 2d183c841d2bb..7d77d5452e0c8 100644 --- a/javascript/firefox-driver/js/syntheticMouse.js +++ b/javascript/firefox-driver/js/syntheticMouse.js @@ -107,8 +107,9 @@ SyntheticMouse.prototype.move = function(target, xOffset, yOffset) { // Are we about to be dragged out of the window? var isOption = bot.dom.isElement(element, goog.dom.TagName.OPTION); + var isSVG = Utils.isSVG(element.ownerDocument); - if (!isOption && !inViewAfterScroll) { + if (!isOption && !isSVG && !inViewAfterScroll) { return SyntheticMouse.newResponse(bot.ErrorCode.MOVE_TARGET_OUT_OF_BOUNDS, 'Element cannot be scrolled into view:' + element); } diff --git a/javascript/firefox-driver/js/utils.js b/javascript/firefox-driver/js/utils.js index 29a7e3970c3f4..4557493c4012d 100644 --- a/javascript/firefox-driver/js/utils.js +++ b/javascript/firefox-driver/js/utils.js @@ -148,7 +148,7 @@ Utils.getActiveElement = function(doc) { // Default to the body if (!element) { - element = doc.body; + element = Utils.getMainDocumentElement(doc); } return element; @@ -1176,8 +1176,8 @@ Utils.getPageUnloadedIndicator = function(element) { var unloadFunction = function() { toReturn.wasUnloaded = true }; toReturn.callback = unloadFunction; - element.ownerDocument.body.addEventListener('unload', - unloadFunction, false); + var mainDocumentElement = Utils.getMainDocumentElement(element.ownerDocument); + mainDocumentElement.addEventListener('unload', unloadFunction, false); // This is a Firefox specific event - See: // https://developer.mozilla.org/En/Using_Firefox_1.5_caching @@ -1191,8 +1191,9 @@ Utils.removePageUnloadEventListener = function(element, pageUnloadData) { if (pageUnloadData.callback) { // Remove event listeners... if (element.ownerDocument) { - if (element.ownerDocument.body) { - element.ownerDocument.body.removeEventListener('unload', + var mainDocumentElement = Utils.getMainDocumentElement(element.ownerDocument); + if (mainDocumentElement) { + mainDocumentElement.removeEventListener('unload', pageUnloadData.callback, false); } if (element.ownerDocument.defaultView) { @@ -1227,3 +1228,13 @@ Utils.convertNSIArrayToNative = function(arrayToConvert) { return returnArray; }; + +Utils.isSVG = function(doc) { + return doc.documentElement && doc.documentElement.nodeName == 'svg'; +}; + +Utils.getMainDocumentElement = function(doc) { + if (Utils.isSVG(doc)) + return doc.documentElement; + return doc.body; +}; diff --git a/javascript/firefox-driver/js/wrappedElement.js b/javascript/firefox-driver/js/wrappedElement.js index 1e08cc13190c7..5f15cfe290d31 100644 --- a/javascript/firefox-driver/js/wrappedElement.js +++ b/javascript/firefox-driver/js/wrappedElement.js @@ -87,7 +87,9 @@ WebElement.clickElement = function(respond, parameters) { unwrapped, new goog.math.Coordinate(elementHalfWidth, elementHalfHeight)); - if (!inViewAfterScroll) { + var isSVG = Utils.isSVG(element.ownerDocument); + + if (!isSVG && !inViewAfterScroll) { respond.sendError( new WebDriverError(bot.ErrorCode.MOVE_TARGET_OUT_OF_BOUNDS, 'Element cannot be scrolled into view:' + element)); @@ -388,7 +390,7 @@ WebElement.getElementLocationOnceScrolledIntoView = function( respond.session.getDocument()); var theDoc = element.ownerDocument; - theDoc.body.focus(); + Utils.getMainDocumentElement(theDoc).focus(); var elementLocation = Utils.getLocationOnceScrolledIntoView(element); respond.value = {