Fix selenium webrat tests in FF/Safari -- locatedLabel.htmlFor returns empty string in FF/Safari which breaks location strategy for label

This commit is contained in:
Noah Davis 2010-04-20 23:44:08 -04:00
parent 68d5fde17a
commit 80ea640901
1 changed files with 8 additions and 2 deletions

View File

@ -10,7 +10,7 @@ RegExp.escape = function(text) {
);
}
return text.replace(arguments.callee.sRE, '\\$1');
}
};
var allLabels = inDocument.getElementsByTagName("label");
var regExp = new RegExp('^\\W*' + RegExp.escape(locator) + '(\\b|$)', 'i');
@ -30,7 +30,13 @@ candidateLabels = candidateLabels.sortBy(function(s) {
});
var locatedLabel = candidateLabels.first();
var labelFor = locatedLabel.getAttribute('for') || locatedLabel.htmlFor;
var labelFor = null;
if (locatedLabel.getAttribute('for')) {
labelFor = locatedLabel.getAttribute('for');
} else if (locatedLabel.attributes['for']) { // IE
labelFor = locatedLabel.attributes['for'].nodeValue;
}
if ((labelFor == null) && (locatedLabel.hasChildNodes())) {
return locatedLabel.getElementsByTagName('button')[0]