Method: Selenium::WebDriver::Support::Select#select_by

Defined in:
lib/selenium/webdriver/support/select.rb

#select_by(how, what) ⇒ Object

Select options by visible text, index or value.

When selecting by :text, selects options that display text matching the argument. That is, when given “Bar” this would select an option like:

<option value="foo">Bar</option>

When selecting by :value, selects all options that have a value matching the argument. That is, when given “foo” this would select an option like:

<option value="foo">Bar</option>

When selecting by :index, selects the option at the given index. This is done by examining the “index” attribute of an element, and not merely by counting.

Parameters:

  • how (:text, :index, :value)

    How to find the option

  • what (String)

    What value to find the option by.

[View source]

101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/selenium/webdriver/support/select.rb', line 101

def select_by(how, what)
  case how
  when :text
    select_by_text what
  when :index
    select_by_index what
  when :value
    select_by_value what
  else
    raise ArgumentError, "can't select options by #{how.inspect}"
  end
end