#221 ✓resolved

webratlink locator for selenium does not find links by id or name

Reported by dstar | April 17th, 2009 @ 12:17 PM

The webratlink locator for selenium only finds links by text, which means that the click_link API differs for selenium and non-selenium tests. The following patch finds links by ID as well, and adding name support should be trivial.

This may not be the best solution (it might be better to not add the evalregexp: prefix in adjust_if_regexp (and remove the leading and trailing slashes if it is a regexp) and instead have the first argument to PatternMatcher.matches be 'evalregexp:/'+locator+'/', so that the lastIndexOf and substring calls aren't needed), but it was good enough to allow my tests to work, which was all I needed.

diff --git a/lib/webrat/selenium/location_strategy_javascript/webratlink.js b/lib/webrat/selenium/location_strategy_javascript/web
index ad71957..4578291 100644
--- a/lib/webrat/selenium/location_strategy_javascript/webratlink.js +++ b/lib/webrat/selenium/location_strategy_javascript/webratlink.js @@ -3,7 +3,14 @@ var candidateLinks = $A(links).select(function(candidateLink) { return PatternMatcher.matches(locator, getText(candidateLink)); }); if (candidateLinks.length == 0) { - return null; + var last_char_of_locator = locator.lastIndexOf('/'); + var locator_id = locator.substring(11,last_char_of_locator); + var candidate_link_by_id = inDocument.getElementById(locator_id); + if (candidate_link_by_id == null) { + return null; + } else { + return candidate_link_by_id; + } } candidateLinks = candidateLinks.sortBy(function(s) { return s.length * -1; }); //reverse length sort return candidateLinks.first();

Comments and changes to this ticket

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

Ruby Acceptance Testing for Web applications.

Shared Ticket Bins

People watching this ticket


Referenced by