Class: Capybara::UI::Select

Inherits:
Field show all
Defined in:
lib/capybara/ui/widgets/select.rb

Overview

A select.

Defined Under Namespace

Modules: Selectable

Constant Summary

Constants included from Capybara::UI

VERSION

Instance Attribute Summary

Attributes inherited from Widget

#root

Instance Method Summary collapse

Methods inherited from Field

root

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

#form, #list, #widget

Methods included from WidgetParts::Container

#has_widget?, #not_visible?, #visible?, #widget, #widgets

Methods included from Capybara::UI

#deprecate

Methods included from Constructors

#Decimal, #Integer, #Widget

Methods included from WidgetParts::Struct

included

Constructor Details

This class inherits a constructor from Capybara::UI::Widget

Instance Method Details

#getString


26
27
28
# File 'lib/capybara/ui/widgets/select.rb', line 26

def get
  selected.text unless selected.nil?
end

#selectedObject


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)
  widget(:option, option).select
rescue
  begin
    widget(:option_by_value, option).select
  rescue Capybara::UI::MissingWidget => e
    raise InvalidOption.new(e.message).
      tap { |x| x.set_backtrace e.backtrace }
  end
end

#to_cellObject


54
55
56
# File 'lib/capybara/ui/widgets/select.rb', line 54

def to_cell
  get
end

#to_sObject


52
# File 'lib/capybara/ui/widgets/select.rb', line 52

def_delegator :get, :to_s

#valueString


31
32
33
# File 'lib/capybara/ui/widgets/select.rb', line 31

def value
  selected.value unless selected.nil?
end