Extend a Locator Strategy

From STIQ

Jump to: navigation, search

Add a valuerepeated= locator, that finds the first element a value attribute equal to the supplied value repeated.


    // The "inDocument" is the document you are searching.
     PageBot.prototype.locateElementByValueRepeated = function(text, inDocument) {

   // Create the text to search for
    var expectedValue = text + text;

   // Loop through all elements, looking for ones that have 
   // a value === our expected value
    var allElements = inDocument.getElementsByTagName("*");
    for (var i = 0; i < allElements.length; i++) {
       var testElement = allElements[i];
        if (testElement.value && testElement.value === expectedValue) {
            return testElement;
        }
    }
    return null;
};
Personal tools
Noteworthy