* @param step The calling step, for exception.
* @return The selected field
*/
public static HtmlElement selectField(final List fieldList, final String indexStr, final Step step) {
if (fieldList.isEmpty()) {
throw new StepFailedException("No suitable field(s) found", step);
}
int numFieldsFound = fieldList.size();
int index;
if (StringUtils.isEmpty(indexStr)) {
LOG.info("Found " + numFieldsFound + " suitable fields, considering only the first one");
index = 0;
} else {
index = ConversionUtil.convertToInt(indexStr, 0);
if (index < 0 || index >= numFieldsFound) {
throw new StepFailedException("Can't set field with index '" + index + "', valid range is 0.." + (numFieldsFound - 1), step);
}
}
return (HtmlElement) fieldList.get(index);
}