Class: Watir::Select

Inherits:
Object
  • Object
show all
Defined in:
lib/watir-formhandler/select.rb

Overview

Extends the Watir::Select class for the #set and #field_value methods and also adds the means to select multiple options when possible.

Instance Method Summary collapse

Instance Method Details

#field_valueString+

Selected option(s) of this Select.

Returns:

  • (String, Array<String>)

    if only one option is selected, return it as string, otherwise, return it as an array of strings.



32
33
34
35
# File 'lib/watir-formhandler/select.rb', line 32

def field_value
  opts = selected_options
  opts.count == 1 ? opts.first.text : opts.map(&:text)
end

#select_multiple(*values) ⇒ Array<String>

Selects the given options of this Select.

Parameters:

  • values (Array<String>)

    to be selected.

Returns:

  • (Array<String>)

    the selected values.



23
24
25
26
# File 'lib/watir-formhandler/select.rb', line 23

def select_multiple(*values)
  clear
  values.flatten.each{ |value| select(value) }
end

#set(*values) ⇒ String+

Selects the given option(s) of this Select. If this Select has the ‘multiple’ attribute, it accept an array, otherwise it will call the internal ‘#select’ method.

Parameters:

  • values (String, Array<String>)

    the values to be selected.

Returns:

  • (String, Array<String>)

    the selected values.



11
12
13
14
15
16
17
# File 'lib/watir-formhandler/select.rb', line 11

def set(*values)
  if multiple?
    select_multiple(*values)
  else
    select(values.first)
  end
end