From 03f2023117163b855f447ef842712f549e6235a4 Mon Sep 17 00:00:00 2001 From: Bryan Helmkamp Date: Fri, 18 Sep 2009 15:48:08 -0400 Subject: [PATCH] Make link location in Selenium more reliable and consistent with non-Selenium --- .../webratlink.js | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/lib/webrat/selenium/location_strategy_javascript/webratlink.js b/lib/webrat/selenium/location_strategy_javascript/webratlink.js index b02576a..2f57175 100644 --- a/lib/webrat/selenium/location_strategy_javascript/webratlink.js +++ b/lib/webrat/selenium/location_strategy_javascript/webratlink.js @@ -1,9 +1,21 @@ var links = inDocument.getElementsByTagName('a'); var candidateLinks = $A(links).select(function(candidateLink) { - var textMatched = PatternMatcher.matches(locator, getText(candidateLink)); - var idMatched = PatternMatcher.matches(locator, candidateLink.id); - var titleMatched = PatternMatcher.matches(locator, candidateLink.title); + var textMatched = false; + var titleMatched = false; + var idMatched = false; + + if (getText(candidateLink).toLowerCase().indexOf(locator.toLowerCase()) != -1) { + textMatched = true; + } + + if (candidateLink.title.toLowerCase().indexOf(locator.toLowerCase()) != -1) { + titleMatched = true; + } + + if (candidateLink.id.toLowerCase().indexOf(locator.toLowerCase()) != -1) { + idMatched = true; + } return textMatched || idMatched || titleMatched; }); @@ -15,6 +27,6 @@ if (candidateLinks.length == 0) { //reverse length sort candidateLinks = candidateLinks.sortBy(function(s) { return s.length * -1; -}); +}); return candidateLinks.first();