Class: Capybara::UI::Select
- Defined in:
- lib/capybara/ui/widgets/select.rb
Overview
A select.
Defined Under Namespace
Modules: Selectable
Constant Summary
Constants included from Capybara::UI
Instance Attribute Summary
Attributes inherited from Widget
Instance Method Summary collapse
-
#get ⇒ String
The text of the selected option.
- #selected ⇒ Object
-
#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.
-
#value ⇒ String
The value of the selected option.
Methods inherited from Field
Methods inherited from Widget
action, #class?, #classes, #click, #double_click, filter, filter?, find_all_in, find_in, #has_action?, #hover, #html, #id, #initialize, not_present_in?, present_in?, #right_click, root, selector, #text, widget_delegator
Methods included from Widgets::DSL
Methods included from WidgetParts::Container
#has_widget?, #not_visible?, #visible?, #widget, #widgets
Methods included from Capybara::UI
Methods included from Constructors
Methods included from WidgetParts::Struct
Constructor Details
This class inherits a constructor from Capybara::UI::Widget
Instance Method Details
#get ⇒ String
Returns The text of the selected option.
26 27 28 |
# File 'lib/capybara/ui/widgets/select.rb', line 26 def get selected.text unless selected.nil? end |
#selected ⇒ Object
5 6 7 |
# File 'lib/capybara/ui/widgets/select.rb', line 5 def selected root.all(:xpath, ".//option", visible: true).select(&:selected?).first end |
#set(option) ⇒ Object
Selects the given option
.
You may pass in the option text or value.
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/capybara/ui/widgets/select.rb', line 38 def set(option) (:option, option).select rescue begin (:option_by_value, option).select rescue Capybara::UI::MissingWidget => e raise InvalidOption.new(e.). tap { |x| x.set_backtrace e.backtrace } end end |
#to_cell ⇒ Object
54 55 56 |
# File 'lib/capybara/ui/widgets/select.rb', line 54 def to_cell get end |
#to_s ⇒ Object
Returns the text of the selected option, or the empty string if no option is selected.
52 |
# File 'lib/capybara/ui/widgets/select.rb', line 52 def_delegator :get, :to_s |
#value ⇒ String
Returns The value of the selected option.
31 32 33 |
# File 'lib/capybara/ui/widgets/select.rb', line 31 def value selected.value unless selected.nil? end |