Class: Capybara::Element
Overview
A Element represents a single element on the page. It is possible to interact with the contents of this element the same as with a document:
session = Capybara::Session.new(:rack_test, my_app)
= session.find('#bar') # from Capybara::Node::Finders
.select('Baz', :from => 'Quox') # from Capybara::Node::Actions
Element also has access to HTML attributes and other properties of the element:
.value
.text
[:title]
Instance Attribute Summary
Attributes inherited from Node
Instance Method Summary collapse
-
#[](attribute) ⇒ String
Retrieve the given attribute.
-
#click ⇒ Object
Click the Element.
-
#drag_to(node) ⇒ Object
Drag the element to the given other element.
- #inspect ⇒ Object
-
#native ⇒ Object
The native element from the driver, this allows access to driver specific methods.
-
#node ⇒ Object
deprecated
Deprecated.
node is deprecated, please use #native instead
-
#path ⇒ String
An XPath expression describing where on the page the element can be found.
-
#select_option ⇒ Object
Select this node if is an option element inside a select tag.
-
#set(value) ⇒ Object
Set the value of the form element to the given value.
-
#tag_name ⇒ String
The tag name of the element.
-
#text ⇒ String
The text of the element.
-
#trigger(event) ⇒ Object
Trigger any event on the current element, for example mouseover or focus events.
-
#unselect_option ⇒ Object
Unselect this node if is an option element inside a multiple select tag.
-
#value ⇒ String
The value of the form element.
-
#visible? ⇒ Boolean
Whether or not the element is visible.
Methods inherited from Node
Methods included from Node::Matchers
#has_button?, #has_checked_field?, #has_content?, #has_css?, #has_field?, #has_link?, #has_no_button?, #has_no_content?, #has_no_css?, #has_no_field?, #has_no_link?, #has_no_select?, #has_no_selector?, #has_no_table?, #has_no_xpath?, #has_select?, #has_selector?, #has_table?, #has_unchecked_field?, #has_xpath?
Methods included from Node::Actions
#attach_file, #check, #choose, #click_button, #click_link, #click_link_or_button, #drag, #fill_in, #select, #uncheck, #unselect
Methods included from Node::Finders
#all, #find, #find_button, #find_by_id, #find_field, #find_link, #locate
Constructor Details
This class inherits a constructor from Capybara::Node
Instance Method Details
#[](attribute) ⇒ String
Retrieve the given attribute
element[:title] # => HTML title attribute
101 102 103 |
# File 'lib/capybara/node.rb', line 101 def [](attribute) base[attribute] end |
#click ⇒ Object
Click the Element
143 144 145 |
# File 'lib/capybara/node.rb', line 143 def click base.click end |
#drag_to(node) ⇒ Object
Drag the element to the given other element.
source = page.find('#foo')
target = page.find('#bar')
source.drag_to(target)
197 198 199 |
# File 'lib/capybara/node.rb', line 197 def drag_to(node) base.drag_to(node.base) end |
#inspect ⇒ Object
201 202 203 204 205 |
# File 'lib/capybara/node.rb', line 201 def inspect %(#<Capybara::Element tag="#{tag_name}" path="#{path}">) rescue NotSupportedByDriverError %(#<Capybara::Element tag="#{tag_name}">) end |
#native ⇒ Object
Returns The native element from the driver, this allows access to driver specific methods.
71 72 73 |
# File 'lib/capybara/node.rb', line 71 def native base.native end |
#node ⇒ Object
node is deprecated, please use #native instead
79 80 81 82 |
# File 'lib/capybara/node.rb', line 79 def node Capybara.deprecate("node", "native") native end |
#path ⇒ String
An XPath expression describing where on the page the element can be found
172 173 174 |
# File 'lib/capybara/node.rb', line 172 def path base.path end |
#select_option ⇒ Object
Select this node if is an option element inside a select tag
127 128 129 |
# File 'lib/capybara/node.rb', line 127 def select_option base.select_option end |
#set(value) ⇒ Object
Set the value of the form element to the given value.
119 120 121 |
# File 'lib/capybara/node.rb', line 119 def set(value) base.set(value) end |
#tag_name ⇒ String
Returns The tag name of the element.
151 152 153 |
# File 'lib/capybara/node.rb', line 151 def tag_name base.tag_name end |
#text ⇒ String
Returns The text of the element.
88 89 90 |
# File 'lib/capybara/node.rb', line 88 def text base.text end |
#trigger(event) ⇒ Object
Trigger any event on the current element, for example mouseover or focus events. Does not work in Selenium.
183 184 185 |
# File 'lib/capybara/node.rb', line 183 def trigger(event) base.trigger(event) end |
#unselect_option ⇒ Object
Unselect this node if is an option element inside a multiple select tag
135 136 137 |
# File 'lib/capybara/node.rb', line 135 def unselect_option base.unselect_option end |
#value ⇒ String
Returns The value of the form element.
109 110 111 |
# File 'lib/capybara/node.rb', line 109 def value base.value end |
#visible? ⇒ Boolean
Whether or not the element is visible. Not all drivers support CSS, so the result may be inaccurate.
162 163 164 |
# File 'lib/capybara/node.rb', line 162 def visible? base.visible? end |