Class: Capybara::UI::RadioButton

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

Overview

A radio button.

Constant Summary

Constants included from Capybara::UI

VERSION

Instance Attribute Summary

Attributes inherited from Widget

#root

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Widget

action, #class?, #classes, #click, #double_click, filter, filter?, find_all_in, find_in, #has_action?, #hover, #html, #initialize, not_present_in?, present_in?, #right_click, selector, #text, #to_s, 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

Class Method Details

.root(selector) ⇒ Object


17
18
19
# File 'lib/capybara/ui/widgets/radio_button.rb', line 17

def self.root(selector)
  super(["#{selector}"])
end

Instance Method Details

#getObject

no button is checked.

Returns:

  • the text of the checked button, or an empty string if


22
23
24
25
26
27
28
29
30
# File 'lib/capybara/ui/widgets/radio_button.rb', line 22

def get
  if visible?(:checked_label_by_value, value)
    widget(:checked_label_by_value, value).text
  elsif visible?(:checked_label_by_id, id)
    widget(:checked_label_by_id, id).text
  else
    nil
  end
end

#idString

Returns The id of the checked button.

Returns:

  • (String)

    The id of the checked button.


38
39
40
# File 'lib/capybara/ui/widgets/radio_button.rb', line 38

def id
  visible?(:checked) ? widget(:checked).id : nil
end

#set(str) ⇒ Object

First attempts to choose the button by id or label text Then attempts to choose the button by value


44
45
46
47
48
49
50
51
52
53
# File 'lib/capybara/ui/widgets/radio_button.rb', line 44

def set(str)
  root.choose(str)
rescue
  begin
    widget(:button_by_value, str).root.set(true)
  rescue Capybara::UI::MissingWidget => e
    raise InvalidRadioButton.new(e.message).
      tap { |x| x.set_backtrace e.backtrace }
  end
end

#to_cellObject


59
60
61
# File 'lib/capybara/ui/widgets/radio_button.rb', line 59

def to_cell
  get
end

#valueString

Returns The value of the checked button.

Returns:

  • (String)

    The value of the checked button.


33
34
35
# File 'lib/capybara/ui/widgets/radio_button.rb', line 33

def value
  visible?(:checked) ? widget(:checked).root.value : nil
end