Sha256: ea2102ab13f2d3f0e4cd694d5ae4da8bc50dc6cf790e7f757d016a3e04fa626c
Contents?: true
Size: 1.29 KB
Versions: 11
Compression:
Stored size: 1.29 KB
Contents
// Credit to: http://simonwillison.net/2006/Jan/20/escape/ RegExp.escape = function(text) { if (!arguments.callee.sRE) { var specials = [ '/', '.', '*', '+', '?', '|', '(', ')', '[', ']', '{', '}', '\\' ]; arguments.callee.sRE = new RegExp( '(\\' + specials.join('|\\') + ')', 'g' ); } return text.replace(arguments.callee.sRE, '\\$1'); } var allLabels = inDocument.getElementsByTagName("label"); var regExp = new RegExp('^\\W*' + RegExp.escape(locator) + '(\\b|$)', 'i'); var candidateLabels = $A(allLabels).select(function(candidateLabel){ var labelText = getText(candidateLabel).strip(); return (labelText.search(regExp) >= 0); }); if (candidateLabels.length == 0) { return null; } //reverse length sort candidateLabels = candidateLabels.sortBy(function(s) { return s.length * -1; }); var locatedLabel = candidateLabels.first(); var labelFor = locatedLabel.getAttribute('for'); if ((labelFor == null) && (locatedLabel.hasChildNodes())) { return locatedLabel.getElementsByTagName('button')[0] || locatedLabel.getElementsByTagName('input')[0] || locatedLabel.getElementsByTagName('textarea')[0] || locatedLabel.getElementsByTagName('select')[0]; } return selenium.browserbot.locationStrategies['id'].call(this, labelFor, inDocument, inWindow);
Version data entries
11 entries across 11 versions & 7 rubygems