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..2a9dc72872ac0 100644 --- a/javascript/firefox-driver/js/wrappedElement.js +++ b/javascript/firefox-driver/js/wrappedElement.js @@ -388,7 +388,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 = {