Class: Dill::Select

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

Overview

A select.

Defined Under Namespace

Modules: Selectable

Constant Summary

Constants included from Dill

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, filter, filter?, find_all_in, find_in, #has_action?, #hover, #html, #id, #initialize, not_present_in?, present_in?, 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 Dill

#deprecate

Methods included from Constructors

#Decimal, #Integer, #Widget

Methods included from WidgetParts::Struct

included

Constructor Details

This class inherits a constructor from Dill::Widget

Instance Method Details

#getString

Returns The text of the selected option.

Returns:

  • (String)

    The text of the selected option.



25
26
27
# File 'lib/dill/widgets/select.rb', line 25

def get
  selected.text unless selected.nil?
end

#selectedObject



4
5
6
# File 'lib/dill/widgets/select.rb', line 4

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.



37
38
39
40
41
42
43
44
45
46
# File 'lib/dill/widgets/select.rb', line 37

def set(option)
  widget(:option, option).select
rescue
  begin
    widget(:option_by_value, option).select
  rescue Dill::MissingWidget => e
    raise InvalidOption.new(e.message).
      tap { |x| x.set_backtrace e.backtrace }
  end
end

#to_cellObject



53
54
55
# File 'lib/dill/widgets/select.rb', line 53

def to_cell
  get
end

#to_sObject

Returns the text of the selected option, or the empty string if no option is selected.

Returns:

  • the text of the selected option, or the empty string if no option is selected.



51
# File 'lib/dill/widgets/select.rb', line 51

def_delegator :get, :to_s

#valueString

Returns The value of the selected option.

Returns:

  • (String)

    The value of the selected option.



30
31
32
# File 'lib/dill/widgets/select.rb', line 30

def value
  selected.value unless selected.nil?
end