Ever try to complete a form, start typing “Dec”, hoping “December” would be selected? And instead the list value reads “(12) December”.
Or perhaps the list contains static and dynamic values within each option.
Using the following function, you can lookup the full or actual list value:
function getItemFullStringValue(obj, subStr){ listObj = waitForObject(obj); listObjArray = listObj.options(); subStrRegex = new RegExp(subStr, "i"); for(var i=0; i < listObjArray.length; i++){ fullString = listObjArray.at(i).text; if(subStrRegex.test(fullString)){ test.log("String found at index " + i + "."); return fullString; } } test.fail("Sub-string " + subStr + " not found."); return false; }
How to call the function, and select the returned value in a list
[...] listItemString = getItemFullStringValue(":Object_Symbolic_Name_Or_Real_Name", partialListItemString); selectOption(waitForObject(":Object_Symbolic_Name_Or_Real_Name"), listItemString); [...]