Class: CongressForms::Actions::Select

Inherits:
Base
  • Object
show all
Defined in:
lib/congress_forms/actions.rb

Instance Attribute Summary

Attributes inherited from Base

#options, #required, #selector, #value

Instance Method Summary collapse

Methods inherited from Base

#escape_css_attribute, #initialize, #inspect, #max_length, #placeholder_value?, #select_options, #submit?

Constructor Details

This class inherits a constructor from CongressForms::Actions::Base

Instance Method Details

#perform(browser, params = {}) ⇒ Object



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/congress_forms/actions.rb', line 93

def perform(browser, params={})
  user_value = params[value]

  browser.within(selector) do
    if placeholder_value?
      option_value = user_value or
        raise Error, "Required field missing: #{value}"
    else
      option_value = value
    end

    begin
      elem = browser.first('option[value="' + escape_css_attribute(option_value) + '"]')
    rescue Capybara::ElementNotFound
      elem = browser.first('option', text: Regexp.compile("^" + Regexp.escape(option_value) + "(\\W|$)"))
    end

    elem.select_option
  end
rescue Capybara::ElementNotFound => e
  raise e, e.message unless options == "DEPENDENT"
end