From 80ea640901b2495e184780932647f7418bb91b31 Mon Sep 17 00:00:00 2001 From: Noah Davis Date: Tue, 20 Apr 2010 23:44:08 -0400 Subject: [PATCH] Fix selenium webrat tests in FF/Safari -- locatedLabel.htmlFor returns empty string in FF/Safari which breaks location strategy for label --- .../selenium/location_strategy_javascript/label.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) 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]