Skip to content
This repository has been archived by the owner on Nov 19, 2021. It is now read-only.

Commit

Permalink
Fix selenium webrat tests in FF/Safari -- locatedLabel.htmlFor return…
Browse files Browse the repository at this point in the history
…s empty string in FF/Safari which breaks location strategy for label
  • Loading branch information
noahd1 committed Apr 21, 2010
1 parent 68d5fde commit 80ea640
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions lib/webrat/selenium/location_strategy_javascript/label.js
Expand Up @@ -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');
Expand All @@ -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]
Expand Down

0 comments on commit 80ea640

Please sign in to comment.