diff --git a/lib/webrat/selenium/location_strategy_javascript/label.js b/lib/webrat/selenium/location_strategy_javascript/label.js index b5dc731..816e69b 100644 --- a/lib/webrat/selenium/location_strategy_javascript/label.js +++ b/lib/webrat/selenium/location_strategy_javascript/label.js @@ -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]