Locate an input field of a given value

    This first looks for the value as the id of the element, then
    the name of the element, then a label for the element.
485630
def find_field(browser, field, value):
    
    return find_field_by_id(browser, field, value) + \
        find_field_by_name(browser, field, value) + \
        find_field_by_label(browser, field, value)
354962
function (input) {

            var value;

            // Get the value or state of the input based on its type
            switch ($(input).attr('type')) {
                case 'checkbox':
                    value = ($(input).is(':checked')) ? 1 : '';
                    break;
                case 'radio':
                    value = node.find('input[name="' + $(input).attr('name') + '"]:checked').val() || '';
                    break;
                default:
                    value = $(input).val();
                    break;
            }

            return value;

        }
1129245
def enter_text_with_id(textfield_id, value, opts = {})
      # For IE10, it seems unable to identify HTML5 elements
      #
      # However for IE10, the '.' is omitted.
      if opts.nil? || opts.empty?
        # for Watir, default is clear 
        opts[:appending] = false
      end
      
      perform_operation {
        
        begin
          text_field(:id, textfield_id).set(value)
        rescue => e
          # However, this approach is not reliable with Watir (IE)
          # for example, for entering email, the dot cannot be entered, try ["a@b", :decimal, "com"]
          the_elem = element(:xpath, "//input[@id='#{textfield_id}']")        
          the_elem.send_keys(:clear) unless opts[:appending]        
          the_elem.send_keys(value)        
        end
      }
    end
461781
def set_input_by_xpath(self, xpath, value):
        

        elem = self.select(xpath).node()

        if self._lxml_form is None:
            # Explicitly set the default form
            # which contains found element
            parent = elem
            while True:
                parent = parent.getparent() # pylint: disable=no-member
                if parent.tag == 'form':
                    self._lxml_form = parent
                    break

        # pylint: disable=no-member
        return self.set_input(elem.get('name'), value)
97653
function(option, inputValue) {
		var optVal = option.value.toLowerCase(),
			inptVal = inputValue.toLowerCase(),
			label = option.getAttribute('label'),
			text = option.text.toLowerCase();

		/*
		"Each option element that is a descendant of the datalist element, that is not disabled, and whose value is a string that isn't the empty string, represents a suggestion. Each suggestion has a value and a label."
		"If appropriate, the user agent should use the suggestion's label and value to identify the suggestion to the user."
		*/
		return Boolean(
			option.disabled === false &&
				((optVal !== '' && optVal.indexOf(inptVal) !== -1) ||
					(label && label.toLowerCase().indexOf(inptVal) !== -1) ||
					(text !== '' && text.indexOf(inptVal) !== -1))
		);
	}
270039
function( name, value, options, checked ) {
        options = options || {};
        if(checked) options.checked = "checked";
        return this.input_field_tag(name, value, 'checkbox', options);
    }
723499
function(value) {
	      
	   // Div that wraps the deleteButton + the subField
	   var newDiv = inputEx.cn('div'), delButton;
	      
	   // Delete button
	   if(this.options.useButtons) {
	      delButton = inputEx.cn('img', {src: inputEx.spacerUrl, className: 'inputEx-ListField-delButton'});
	      Event.addListener( delButton, 'click', this.onDelete, this, true);
	      newDiv.appendChild( delButton );
      }
	      
	   // Instantiate the new subField
	   var opts = lang.merge({}, this.options.elementType);
	   
	   // Retro-compatibility with deprecated inputParams Object : TODO -> remove
      if(lang.isObject(opts.inputParams) && !lang.isUndefined(value)) {
         opts.inputParams.value = value;
         
      // New prefered way to set options of a field
      } else if (!lang.isUndefined(value)) {
         opts.value = value;
      }
	   
	   var el = inputEx(opts,this);
	   
	   var subFieldEl = el.getEl();
		YAHOO.util.Dom.addClass(subFieldEl, 'inputEx-ListField-subFieldEl');
	   newDiv.appendChild( subFieldEl );
	   
	   // Subscribe the onChange event to resend it 
	   el.updatedEvt.subscribe(this.onChange, this, true);
	
	   // Arrows to order:
	   if(this.options.sortable) {
	      var arrowUp = inputEx.cn('div', {className: 'inputEx-ListField-Arrow inputEx-ListField-ArrowUp'});
	      Event.addListener(arrowUp, 'click', this.onArrowUp, this, true);
	      var arrowDown = inputEx.cn('div', {className: 'inputEx-ListField-Arrow inputEx-ListField-ArrowDown'});
	      Event.addListener(arrowDown, 'click', this.onArrowDown, this, true);
	      newDiv.appendChild( arrowUp );
	      newDiv.appendChild( arrowDown );
	   }
	   
	   // Delete link
	   if(!this.options.useButtons) {
	      delButton = inputEx.cn('a', {className: 'inputEx-List-link'}, null, this.options.listRemoveLabel);
	      Event.addListener( delButton, 'click', this.onDelete, this, true);
	      newDiv.appendChild( delButton );
      }
	
	   // Line breaker
	   newDiv.appendChild( inputEx.cn('div', null, {clear: "both"}) );
	
	   this.childContainer.appendChild(newDiv);
	      
	   return el;
	}
183149
private function AddLabelField()
    {
        $name = 'Label';
        $field = Input::Text($name, $this->select->GetLabel());
        $this->AddField($field);
    }
289909
def value(self, value):
        
        self.client.nowait(
            'set_field', (Literal('browser'), self.element, value))
1151985
def start_element(self, tag, attrs):
        """"""
        if tag == u'form':
            if u'action' in attrs:
                url = attrs['action']
                self.form = Form(url)
        elif tag == u'input':
            if self.form:
                if 'name' in attrs:
                    key = attrs['name']
                    value = attrs.get('value')
                    self.form.add_value(key, value)
                else:
                    log.warning(LOG_CHECK, "nameless form input %s" % attrs)
                    pass
            else:
                log.warning(LOG_CHECK, "formless input´%s" % attrs)
                pass
733149
def _set_input(el, value):
        
        if isinstance(value, dict):
            el.value = value["val"]
        elif type(value) in [list, tuple]:
            el.value = ", ".join(item["val"] for item in value)
        else:
            el.value = value
266101
public function setLabel()
    {
        if($this->settings->getValue(InputSettings::LABEL_PARAM)) {
            $this->element->setLabel($this->settings->getValue(InputSettings::LABEL_PARAM));
        } else {
            $this->element->setLabel(preg_replace('/.*\\\/', '', get_class($this)));
        }
    }
799624
def click_on_label(step, label):
    

    with AssertContextManager(step):
        elem = world.browser.find_element_by_xpath(str(
            '//label[normalize-space(text()) = "%s"]' % label))
        elem.click()
72271
def __get_default_value_from_element(self, element):
        

        if element.name == "select":
            options = element.find_all("option")
            is_multiple = element.has_attr("multiple")

            selected_options = [
                option for option in options
                if option.has_attr("selected")
            ]

            if not selected_options and options:
                selected_options = [options[0]]

            selected_values = []

            if is_multiple:
                for option in selected_options:
                    value = option["value"] if option.has_attr("value") else option.string
                    selected_values.append(value)

                return selected_values
            elif len(selected_options) >= 1:
                if selected_options[0].has_attr("value"):
                    return selected_options[0]["value"]
                else:
                    return selected_options[0].string

            return ""

        if element.name == "textarea":
            return element.string if element.string is not None else ""

        if element.name == "input" and element.has_attr("type"):
            if element["type"] in ("checkbox", "radio"):
                if not element.has_attr("checked"):
                    return False

                if element.has_attr("value"):
                    return element["value"]
                else:
                    return "on"

        if element.has_attr("value"):
            return element["value"]

        return ""
913733
def find_field_by_value(browser, field_type, name):
    
    xpath = field_xpath(field_type, 'value') % string_literal(name)
    elems = ElementSelector(
        browser,
        xpath=str(xpath),
        filter_displayed=True,
        filter_enabled=True,
    )

    # sort by shortest first (most closely matching)
    if field_type in ('button-element', 'button-role'):
        elems = sorted(elems, key=lambda elem: len(elem.text))
    else:
        elems = sorted(elems,
                       key=lambda elem: len(elem.get_attribute('value')))

    if elems:
        elems = [elems[0]]

    return ElementSelector(browser, elements=elems)
421036
def input_has_value(self, field_name, value):
    
    text_field = find_any_field(world.browser,
                                DATE_FIELDS + TEXT_FIELDS,
                                field_name)
    if text_field is False:
        raise AssertionError(
            "Can not find a field named {!r}.".format(field_name))

    actual = text_field.get_attribute('value')
    if actual != value:
        raise AssertionError(
            "Field value expected to be {!r}, got {!r}.".format(
                value, actual))
313153
def set_input_by_number(self, number, value):
        

        sel = XpathSelector(self.form)
        elem = sel.select('.//input[@type="text"]')[number].node()
        return self.set_input(elem.get('name'), value)