Class: Webrat::Locators::SelectOptionLocator
- Defined in:
- lib/webrat/core/locators/select_option_locator.rb
Overview
:nodoc:
Instance Method Summary collapse
- #error_message ⇒ Object
-
#initialize(session, dom, option_text, id_or_name_or_label) ⇒ SelectOptionLocator
constructor
A new instance of SelectOptionLocator.
- #locate ⇒ Object
- #option_elements ⇒ Object
Methods inherited from Locator
Constructor Details
#initialize(session, dom, option_text, id_or_name_or_label) ⇒ SelectOptionLocator
Returns a new instance of SelectOptionLocator.
9 10 11 12 13 14 |
# File 'lib/webrat/core/locators/select_option_locator.rb', line 9 def initialize(session, dom, option_text, id_or_name_or_label) @session = session @dom = dom @option_text = option_text @id_or_name_or_label = id_or_name_or_label end |
Instance Method Details
#error_message ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/webrat/core/locators/select_option_locator.rb', line 44 def if @id_or_name_or_label "The '#{@option_text}' option was not found in the #{@id_or_name_or_label.inspect} select box" else "Could not find option #{@option_text.inspect}" end end |
#locate ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/webrat/core/locators/select_option_locator.rb', line 16 def locate if @id_or_name_or_label field = FieldLocator.new(@session, @dom, @id_or_name_or_label, SelectField, MultipleSelectField).locate! field..detect do |o| if @option_text.is_a?(Regexp) o.element.inner_text =~ @option_text else o.inner_text == @option_text.to_s end end else option_element = option_elements.detect do |o| if @option_text.is_a?(Regexp) o.inner_text =~ @option_text else o.inner_text == @option_text.to_s end end SelectOption.load(@session, option_element) end end |
#option_elements ⇒ Object
40 41 42 |
# File 'lib/webrat/core/locators/select_option_locator.rb', line 40 def option_elements @dom.xpath(*SelectOption.xpath_search) end |