Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions javascript/firefox-driver/js/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ Utils.getActiveElement = function(doc) {

// Default to the body
if (!element) {
element = doc.body;
element = Utils.getMainDocumentElement(doc);
}

return element;
Expand Down Expand Up @@ -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
Expand All @@ -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) {
Expand Down Expand Up @@ -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;
};
2 changes: 1 addition & 1 deletion javascript/firefox-driver/js/wrappedElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down