Class: Capybara::Node::Simple
- Inherits:
-
Object
- Object
- Capybara::Node::Simple
- Defined in:
- lib/capybara/node/simple.rb
Overview
A Simple is a simpler version of Base which includes only Finders and Matchers and does not include Actions. This type of node is returned when using Capybara.string.
It is useful in that it does not require a session, an application or a driver, but can still use Capybara’s finders and matchers on any string that contains HTML.
Instance Attribute Summary collapse
-
#native ⇒ Object
readonly
Returns the value of attribute native.
Instance Method Summary collapse
-
#[](name) ⇒ String
Retrieve the given attribute.
- #allow_reload! ⇒ Object
-
#checked? ⇒ Boolean
Whether or not the element is checked.
-
#disabled? ⇒ Boolean
Whether or not the element is disabled.
- #has_no_title?(content) ⇒ Boolean
- #has_title?(content) ⇒ Boolean
-
#initialize(native) ⇒ Simple
constructor
A new instance of Simple.
-
#path ⇒ String
An XPath expression describing where on the page the element can be found.
-
#selected? ⇒ Boolean
Whether or not the element is selected.
- #synchronize(seconds = nil) ⇒ Object
-
#tag_name ⇒ String
The tag name of the element.
-
#text(type = nil) ⇒ String
The text of the element.
- #title ⇒ Object
-
#value ⇒ String
The value of the form element.
-
#visible? ⇒ Boolean
Whether or not the element is visible.
Methods included from Matchers
#==, #assert_no_selector, #assert_selector, #has_button?, #has_checked_field?, #has_css?, #has_field?, #has_link?, #has_no_button?, #has_no_checked_field?, #has_no_css?, #has_no_field?, #has_no_link?, #has_no_select?, #has_no_selector?, #has_no_table?, #has_no_text?, #has_no_unchecked_field?, #has_no_xpath?, #has_select?, #has_selector?, #has_table?, #has_text?, #has_unchecked_field?, #has_xpath?
Methods included from Finders
#all, #find, #find_button, #find_by_id, #find_field, #find_link, #first
Constructor Details
Instance Attribute Details
#native ⇒ Object (readonly)
Returns the value of attribute native.
18 19 20 |
# File 'lib/capybara/node/simple.rb', line 18 def native @native end |
Instance Method Details
#[](name) ⇒ String
Retrieve the given attribute
element[:title] # => HTML title attribute
42 43 44 45 46 47 48 49 50 51 |
# File 'lib/capybara/node/simple.rb', line 42 def [](name) attr_name = name.to_s if attr_name == 'value' value elsif 'input' == tag_name and 'checkbox' == native[:type] and 'checked' == attr_name native['checked'] == 'checked' else native[attr_name] end end |
#allow_reload! ⇒ Object
136 137 138 |
# File 'lib/capybara/node/simple.rb', line 136 def allow_reload! # no op end |
#checked? ⇒ Boolean
Whether or not the element is checked.
109 110 111 |
# File 'lib/capybara/node/simple.rb', line 109 def checked? native[:checked] end |
#disabled? ⇒ Boolean
Whether or not the element is disabled.
118 119 120 |
# File 'lib/capybara/node/simple.rb', line 118 def disabled? native[:disabled] end |
#has_no_title?(content) ⇒ Boolean
148 149 150 |
# File 'lib/capybara/node/simple.rb', line 148 def has_no_title?(content) not has_title?(content) end |
#has_title?(content) ⇒ Boolean
144 145 146 |
# File 'lib/capybara/node/simple.rb', line 144 def has_title?(content) title.match(Capybara::Helpers.to_regexp(content)) end |
#path ⇒ String
An XPath expression describing where on the page the element can be found
67 68 69 |
# File 'lib/capybara/node/simple.rb', line 67 def path native.path end |
#selected? ⇒ Boolean
Whether or not the element is selected.
128 129 130 |
# File 'lib/capybara/node/simple.rb', line 128 def selected? native[:selected] end |
#synchronize(seconds = nil) ⇒ Object
132 133 134 |
# File 'lib/capybara/node/simple.rb', line 132 def synchronize(seconds=nil) yield # simple nodes don't need to wait end |
#tag_name ⇒ String
Returns The tag name of the element.
57 58 59 |
# File 'lib/capybara/node/simple.rb', line 57 def tag_name native.node_name end |
#text(type = nil) ⇒ String
Returns The text of the element.
29 30 31 |
# File 'lib/capybara/node/simple.rb', line 29 def text(type=nil) native.text end |
#title ⇒ Object
140 141 142 |
# File 'lib/capybara/node/simple.rb', line 140 def title native.xpath("//title").first.text end |
#value ⇒ String
Returns The value of the form element.
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/capybara/node/simple.rb', line 75 def value if tag_name == 'textarea' native.content elsif tag_name == 'select' if native['multiple'] == 'multiple' native.xpath(".//option[@selected='selected']").map { |option| option[:value] || option.content } else option = native.xpath(".//option[@selected='selected']").first || native.xpath(".//option").first option[:value] || option.content if option end elsif tag_name == 'input' && %w(radio checkbox).include?(native[:type]) native[:value] || 'on' else native[:value] end end |
#visible? ⇒ Boolean
Whether or not the element is visible. Does not support CSS, so the result may be inaccurate.
99 100 101 |
# File 'lib/capybara/node/simple.rb', line 99 def visible? native.xpath("./ancestor-or-self::*[contains(@style, 'display:none') or contains(@style, 'display: none') or @hidden or name()='script' or name()='head']").size == 0 end |