Fix "element.getAttribute is not a function" Selenium errors when filling in fields

The root cause was the locator strategy was naively returning an element that was not a form field, causing Selenium's internals to blow up
This commit is contained in:
Bryan Helmkamp 2009-09-17 21:32:56 -04:00
parent 3a9e7d3999
commit c689166c48
1 changed files with 5 additions and 2 deletions

View File

@ -1,3 +1,4 @@
// Credit to: http://simonwillison.net/2006/Jan/20/escape/
RegExp.escape = function(text) {
if (!arguments.callee.sRE) {
var specials = [
@ -32,8 +33,10 @@ var locatedLabel = candidateLabels.first();
var labelFor = locatedLabel.getAttribute('for');
if ((labelFor == null) && (locatedLabel.hasChildNodes())) {
// TODO: should find the first form field, not just any node
return locatedLabel.firstChild;
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);