Select an individual input from within a group, matched by the top-most label.

@Given /^I select "([^"]*)" from "([^"]*)" input group$/
548704
public function iSelectFromInputGroup($value, $labelText) {
		$page = $this->getSession()->getPage();
		$parent = null;

		foreach($page->findAll('css', 'label') as $label) {
			if($label->getText() == $labelText) {
				$parent = $label->getParent();
			}
		}

		if(!$parent) throw new \InvalidArgumentException(sprintf('Input group with label "%s" cannot be found', $labelText));

		foreach($parent->findAll('css', 'label') as $option) {
			if($option->getText() == $value) {
				$for = $option->getAttribute('for');
				$input = $parent->findById($for);

				if(!$input) throw new \InvalidArgumentException(sprintf('Input "%s" cannot be found', $value));

				$this->getSession()->getDriver()->click($input->getXPath());
			}
		}
	}
419422
function filterDomElement(domElement, names, labels) {
			/*
			 Where we look to find a match, in this order:
			 name, id, <label> tags, placeholder, title
			 Our searches first conduct fairly liberal "contains" searches:
			 if the attribute even contains the name or label, we map it.
			 The names and labels we choose to find are very particular.
			 */

			var name = lowercase(domElement.name);
			var id = lowercase(domElement.id);
			var selectorSafeID = id.replace(/[\[|\]|\(|\)|\:|\'|\"|\=|\||\#|\.|\!|\||\@|\^|\&|\*]/g, "\\\\$&");
			var placeholder = lowercase(domElement.placeholder);
			var title = lowercase(domElement.title);

			// First look through name and id attributes of the element, the most common
			for (var i = 0; i < names.length; i++)
				if (name.indexOf(names[i]) > -1 || id.indexOf(names[i]) > -1)
					return true;

			// If we can't find it in name or id, look at labels associated to the element.
			// Webkit automatically associates labels with form elements for us. But for other
			// browsers, we have to find them manually, which this next block does.
			if (!("labels" in domElement)) {
				var lbl = $("label[for=\"" + selectorSafeID + "\"]")[0] || $(domElement).parents("label")[0];
				domElement.labels = !lbl ? [] : [lbl];
			}

			// Iterate through the <label> tags now to search for a match.
			for (var i = 0; i < domElement.labels.length; i++) {
				// This inner loop compares each label value with what we're looking for
				for (var j = 0; j < labels.length; j++)
					if ($(domElement.labels[i]).text().toLowerCase().indexOf(labels[j]) > -1)
						return true;
			}

			// Still not found? Then look in "placeholder" or "title"...
			for (var i = 0; i < labels.length; i++)
				if (placeholder.indexOf(labels[i]) > -1 || title.indexOf(labels[i]) > -1)
					return true;

			// Got all the way to here? Probably not a match then.
			return false;
		}
754658
private static boolean matchLabel(Node target, String label) {
    if (label == null) {
      return true;
    }
    while (target.isLabel()) {
      if (target.getFirstChild().getString().equals(label)) {
        return true;
      }
      target = target.getParent();
    }
    return false;
  }
890976
def select_one(self, tag):
        """"""

        tags = self.select(tag, limit=1)
        return tags[0] if tags else None
989770
function (type) {
      var that = this,
        texts = [],
        labels = [],
        values = [];
      this.$drop.find(sprintf('input[%s]:checked', this.selectItemName)).each(function () {
        texts.push($(this).parents('li').first().text());
        labels.push($(this).parents('li').attr('label') || '');
        values.push($(this).val());
      });

      if (type === 'text' && this.$selectGroups.length) {
        texts = [];
        this.$selectGroups.each(function () {
          var html = [],
            text = $.trim($(this).parent().text()),
            group = $(this).parent().data('group'),
            $children = that.$drop.find(sprintf('[%s][data-group="%s"]', that.selectItemName, group)),
            $selected = $children.filter(':checked');

          if (!$selected.length) {
            return;
          }

          html.push('[');
          html.push(text);
          if ($children.length > $selected.length) {
            var list = [];
            $selected.each(function () {
              list.push($(this).parent().text());
            });
            html.push(': ' + list.join(', '));
          }
          html.push(']');
          texts.push(html.join(''));
        });
      } else if (type === 'label' && this.$selectGroups.length) {
        labels = [];
        this.$selectGroups.each(function () {
          var html = [],
            label = $.trim($(this).attr('label') || ''),
            group = $(this).parent().data('group'),
            $children = that.$drop.find(sprintf('[%s][data-group="%s"]', that.selectItemName, group)),
            $selected = $children.filter(':checked');

          if (!$selected.length) {
            return;
          }

          html.push('[');
          html.push(label);
          if ($children.length > $selected.length) {
            var list = [];
            $selected.each(function () {
              list.push($(this).attr('label') || '');
            });
            html.push(': ' + list.join(', '));
          }
          html.push(']');
          labels.push(html.join(''));
        });
      }

      switch (type) {
        case 'text':
          return texts;
        case 'label':
          return labels;
        default:
          return values;
      }
    }
67571
def ask_select prompt="Enter selection pattern: "
      ret = get_string prompt
      return if ret.nil? || ret ==  ""
      indices = get_matching_indices ret
      #$log.debug "listselectionmodel: ask_select got matches#{@indices} "
      return if indices.nil? || indices.empty?
      indices.each { |e|
        # will not work if single select !! FIXME
        add_row_selection_interval e,e
      }
    end
382969
function getKeyframesSelectorsGroup() {
  let selectorsGroup = [];
  const selectorsGroupEnd = tokens[pos].selectorsGroupEnd;

  selectorsGroup.push(getKeyframesSelector());

  if (checkSC(pos) && tokens[pos].type !== TokenType.Newline) {
    selectorsGroup = selectorsGroup.concat(getSC());
  }

  while (pos < selectorsGroupEnd) {
    selectorsGroup = selectorsGroup.concat(
      getDelim(),
      getSC(),
      getSC(),
      getSC(),
      getKeyframesSelector()
    );

    if (checkSC(pos) && tokens[pos].type !== TokenType.Newline) {
      selectorsGroup = selectorsGroup.concat(getSC());
    }
  }

  return selectorsGroup;
}
1149630
public static function OptionGroup( $label, $options, $selected = NULL )
	{
		$attributes	= array( 'label' => $label );
		$options	= self::Options( $options, $selected );
		return UI_HTML_Tag::create( "optgroup", $options, $attributes );
	}
1237260
private synchronized int getGroupChar(String name, int choice)
    {
        for (int i = 0; i < m_groupcount_; i ++) {
            // populating the data set of grouptable

            int startgpstrindex = getGroupLengths(i, m_groupoffsets_,
                                                  m_grouplengths_);

            // shift out to function
            int result = getGroupChar(startgpstrindex, m_grouplengths_, name,
                                      choice);
            if (result != -1) {
                return (m_groupinfo_[i * m_groupsize_] << GROUP_SHIFT_)
                         | result;
            }
        }
        return -1;
    }
1254100
def get_matched_token(self, match):
        """"""
        match_groupdict = match.groupdict()
        for group in self.groups:
            if match_groupdict[group] is not None:
                token, match_type = self.groups[group]
                return (token, match_type, group)
585909
def ask_select prompt="Enter selection pattern: "
      ret = ask(prompt, String) {|q| yield q if block_given? }
      return if ret.nil? || ret ==  ""
      indices = get_matching_indices ret
      return if indices.nil? || indices.empty?
      indices.each { |e|
        # will not work if single select !! FIXME
        add_row_selection_interval e,e
      }
      @repaint_required = true
    end
909307
function(_input,_clazz){
		        var _id = _e._$id(_input),
		            _label = _e._$wrapInline(_input,{
		                tag:'label',
		                clazz:_clazz,
		                nid:_ropt.nid
		            });
		        _label.htmlFor = _id;
		        var _text = _e._$attr(_input,'placeholder')||'';
		        _label.innerText = _text=='null'?'':_text;
		        var _height = _input.offsetHeight+'px';
		        _e._$style(_label,{
		            left:0,
		            // width:_input.offsetWidth+'px',
		            // height:_height,lineHeight:_height,
		            display:!_input.value?'':'none'
		        });
		    }
389453
function select(word) {	
		var input = this;
		var value = input.val();
		if (word) {
			input.val(
				value
				+ word.substr(value.split(/ |\n/).pop().length)
			);
			
			// Select hint.
			input[0].selectionStart = value.length;
		}
	}
462470
function ( i )
	{
		var
			that = this,
			dt = this.s.dt,
			oGroup = this.s.aoGroups[i];

		return $(
				'<li class="ColVis_Special '+(dt.bJUI ? 'ui-button ui-state-default' : '')+'">'+
					'<label>'+
						'<input type="checkbox" />'+
						'<span>'+oGroup.sTitle+'</span>'+
					'</label>'+
				'</li>'
			)
			.click( function (e) {
				var showHide = !$('input', this).is(":checked");
				if (  e.target.nodeName.toLowerCase() !== "li" )
				{
					showHide = ! showHide;
				}

				for ( var j=0 ; j < oGroup.aiColumns.length ; j++ )
				{
					that.s.dt.oInstance.fnSetColumnVis( oGroup.aiColumns[j], showHide );
				}
			} )[0];
	}
1188018
function getValueLengthThroughSelection(input) {
            // only do this on opera, since it'll mess up the caret position
            // and break Firefox functionality
            if (!/Opera/i.test(navigator.userAgent)) {
              return 0;
            }

            input.focus();
            document.execCommand("selectAll");
            var focusNode = window.getSelection().focusNode;
            return (focusNode || {}).selectionStart || 0;
          }
19090
def pick(self, selector, entity_set, min_quantity=None):
        
        if isinstance(selector, int):
            for e in entity_set:
                if e.id == selector:
                    return set((e,))
        else:
            if selector.lower() in ('self', 'me', 'myself'):
                return set((self.entity,))

            return set(
                e for e in entity_set
                if (e.is_('Named') and selector.lower() in e.Named.name.lower())
                and not e.is_(Invisible)
                and (not min_quantity or min_quantity == 1 or (e.is_(Stackable) and e.Stackable.quantity >= min_quantity))
            )
1348819
def set_selection_for_char char=nil
      char = _ask_a_char unless char
      #alert "got #{char} "
      return :UNHANDLED if char == :UNHANDLED
      @oldrow = @current_index
      @last_regex = /^#{char}/
      ix = next_regex @last_regex
      #alert "next returned #{ix}"
      return unless ix
      @current_index = ix[0] 
      @search_found_ix = @current_index
      @curpos = ix[1]
      ensure_visible
      return @current_index
    end