Class: Capybara::Node::Element

Inherits:
Base
  • Object
show all
Defined in:
lib/capybara/node/element.rb

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)

bar = session.find('#bar')              # from Capybara::Node::Finders
bar.select('Baz', :from => 'Quox')      # from Capybara::Node::Actions

Element also has access to HTML attributes and other properties of the element:

bar.value
bar.text
bar[:title]

See Also:

Instance Attribute Summary

Attributes inherited from Base

#base, #session

Instance Method Summary collapse

Methods inherited from Base

#initialize

Methods included from Matchers

#has_button?, #has_checked_field?, #has_content?, #has_css?, #has_field?, #has_link?, #has_no_button?, #has_no_checked_field?, #has_no_content?, #has_no_css?, #has_no_field?, #has_no_link?, #has_no_select?, #has_no_selector?, #has_no_table?, #has_no_unchecked_field?, #has_no_xpath?, #has_select?, #has_selector?, #has_table?, #has_unchecked_field?, #has_xpath?

Methods included from Actions

#attach_file, #check, #choose, #click_button, #click_link, #click_link_or_button, #fill_in, #select, #uncheck, #unselect

Methods included from Finders

#all, #find, #find_button, #find_by_id, #find_field, #find_link, #first

Constructor Details

This class inherits a constructor from Capybara::Node::Base

Instance Method Details

#[](attribute) ⇒ String

Retrieve the given attribute

element[:title] # => HTML title attribute


50
51
52
# File 'lib/capybara/node/element.rb', line 50

def [](attribute)
  base[attribute]
end

#checked?Boolean

Whether or not the element is checked.



121
122
123
# File 'lib/capybara/node/element.rb', line 121

def checked?
  base.checked?
end

#clickObject

Click the Element



92
93
94
# File 'lib/capybara/node/element.rb', line 92

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)


166
167
168
# File 'lib/capybara/node/element.rb', line 166

def drag_to(node)
  base.drag_to(node.base)
end

#inspectObject



170
171
172
173
174
# File 'lib/capybara/node/element.rb', line 170

def inspect
  %(#<Capybara::Element tag="#{tag_name}" path="#{path}">)
rescue NotSupportedByDriverError
  %(#<Capybara::Element tag="#{tag_name}">)
end

#nativeObject



29
30
31
# File 'lib/capybara/node/element.rb', line 29

def native
  base.native
end

#pathString

An XPath expression describing where on the page the element can be found



141
142
143
# File 'lib/capybara/node/element.rb', line 141

def path
  base.path
end

#select_optionObject

Select this node if is an option element inside a select tag



76
77
78
# File 'lib/capybara/node/element.rb', line 76

def select_option
  base.select_option
end

#selected?Boolean

Whether or not the element is selected.



131
132
133
# File 'lib/capybara/node/element.rb', line 131

def selected?
  base.selected?
end

#set(value) ⇒ Object

Set the value of the form element to the given value.



68
69
70
# File 'lib/capybara/node/element.rb', line 68

def set(value)
  base.set(value)
end

#tag_nameString



100
101
102
# File 'lib/capybara/node/element.rb', line 100

def tag_name
  base.tag_name
end

#textString



37
38
39
# File 'lib/capybara/node/element.rb', line 37

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.



152
153
154
# File 'lib/capybara/node/element.rb', line 152

def trigger(event)
  base.trigger(event)
end

#unselect_optionObject

Unselect this node if is an option element inside a multiple select tag



84
85
86
# File 'lib/capybara/node/element.rb', line 84

def unselect_option
  base.unselect_option
end

#valueString



58
59
60
# File 'lib/capybara/node/element.rb', line 58

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.



111
112
113
# File 'lib/capybara/node/element.rb', line 111

def visible?
  base.visible?
end