getOptionSet

DataSet sutil.getOptionSet ( String options ) (professional and enterprise editions only)
DataSet sutil.getOptionSet ( String options, String ignoreLabel, boolean tidyRecords ) (professional and enterprise editions only)
DataSet sutil.getOptionSet ( String options, String[] ignoreLabels, boolean tidyRecords ) (professional and enterprise editions only)
DataSet sutil.getOptionSet ( String options, Collection<String> ignoreLabels, boolean tidyRecords ) (professional and enterprise editions only)

Description

Gets a DataSet containing each of the elements of a <select> tag. The returned DataRecords will contain a key for the text found between the tags (possibly with html tags removed), a value indicating if it was the selected option, and the value to submit for the specific option. Note that this only looks for option tags, and as such passing in text containing more than a single select tag will produce false output.

Parameters

  • options The text containing the options HTML from the select tag
  • ignoreLabels (or ignoreLabel) (optional) Text value(s) to ignore in the output set. Usually this would include the strings like "Please select a category"
  • tidyRecords (optional) Should the TEXT be tidied before being stored in the resulting DataRecords

Return Values

A DataSet with one record per option. Values extracted will be stored in
VALUE : The value the browser would submit for this option
TEXT : The text that was between the tags
SELECTED : A boolean that is true if this option was selected by default

Change Log

Version Description
5.5.26a Available in all editions.

Examples

Search each option from a dropdown menu

 String options = dataRecord.get("ITEM_OPTIONS");
 
 // We don't want the value for "Select an option" because that doesn't go to a search results page
 DataSet items = sutil.getOptionSet(options, "Select an option", true);
 
 for(int i = 0; i < items.getNumDataRecords(); i++)
 {
   DataRecord next = items.getDataRecord(i);
   session.setVariable("ITEM_VALUE", next.get("VALUE"));
   session.log("Now scraping results for " + next.get("TEXT"));
   session.scrapeFile("Search Results");
 }