Class: Dill::Select
Overview
A select.
Instance Method Summary collapse
-
#get ⇒ String
The text of the selected option.
-
#set(option) ⇒ Object
Selects the given
option
. - #to_cell ⇒ Object
-
#to_s ⇒ Object
The text of the selected option, or the empty string if no option is selected.
Methods inherited from Field
Methods inherited from Widget
#absent?, action, #classes, #click, #diff, filter, filter?, find_all_in, find_in, #gone?, #has_action?, #id, #initialize, #inspect, #present?, present_in?, root, #root, selector, #text, #value, widget_delegator
Methods included from Widgets::DSL
Methods included from WidgetParts::Container
#has_no_widget?, #has_widget?, #widget, #widgets
Methods included from WidgetParts::Struct
Constructor Details
This class inherits a constructor from Dill::Widget
Instance Method Details
#get ⇒ String
Returns The text of the selected option.
5 6 7 8 9 |
# File 'lib/dill/widgets/select.rb', line 5 def get option = root.find('[selected]') rescue nil option && option.text end |
#set(option) ⇒ Object
Selects the given option
.
You may pass in the option text or value.
14 15 16 17 18 19 20 21 22 |
# File 'lib/dill/widgets/select.rb', line 14 def set(option) root.find(:option, option).select_option rescue begin root.find("option[value = #{option.inspect}]").select_option rescue Capybara::ElementNotFound => e raise wrap_exception(e, InvalidOption) end end |
#to_cell ⇒ Object
29 30 31 |
# File 'lib/dill/widgets/select.rb', line 29 def to_cell get end |
#to_s ⇒ Object
Returns the text of the selected option, or the empty string if no option is selected.
27 |
# File 'lib/dill/widgets/select.rb', line 27 def_delegator :get, :to_s |