Class: Capybara::Node::Element
- 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)
= 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 Base
Instance Method Summary collapse
-
#[](attribute) ⇒ String
Retrieve the given attribute.
- #all(*args) ⇒ Object
-
#checked? ⇒ Boolean
Whether or not the element is checked.
-
#click ⇒ Object
Click the Element.
-
#drag_to(node) ⇒ Object
Drag the element to the given other element.
- #find(*args) ⇒ Object
- #first(*args) ⇒ Object
-
#initialize(session, base, parent, selector) ⇒ Element
constructor
A new instance of Element.
- #inspect ⇒ Object
-
#native ⇒ Object
The native element from the driver, this allows access to driver specific methods.
-
#path ⇒ String
An XPath expression describing where on the page the element can be found.
- #reload ⇒ Object
-
#select_option ⇒ Object
Select this node if is an option element inside a select tag.
-
#selected? ⇒ Boolean
Whether or not the element is selected.
-
#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 included from Matchers
#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 Actions
#attach_file, #check, #choose, #click_button, #click_link, #click_link_or_button, #fill_in, #select, #uncheck, #unselect
Methods included from Finders
#find_button, #find_by_id, #find_field, #find_link
Constructor Details
#initialize(session, base, parent, selector) ⇒ Element
Returns a new instance of Element.
25 26 27 28 29 |
# File 'lib/capybara/node/element.rb', line 25 def initialize(session, base, parent, selector) super(session, base) @parent = parent @selector = selector end |
Instance Method Details
#[](attribute) ⇒ String
Retrieve the given attribute
element[:title] # => HTML title attribute
56 57 58 |
# File 'lib/capybara/node/element.rb', line 56 def [](attribute) wait_until { base[attribute] } end |
#all(*args) ⇒ Object
184 185 186 |
# File 'lib/capybara/node/element.rb', line 184 def all(*args) wait_until { super } end |
#checked? ⇒ Boolean
Whether or not the element is checked.
127 128 129 |
# File 'lib/capybara/node/element.rb', line 127 def checked? wait_until { base.checked? } end |
#click ⇒ Object
Click the Element
98 99 100 |
# File 'lib/capybara/node/element.rb', line 98 def click wait_until { 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)
172 173 174 |
# File 'lib/capybara/node/element.rb', line 172 def drag_to(node) wait_until { base.drag_to(node.base) } end |
#find(*args) ⇒ Object
176 177 178 |
# File 'lib/capybara/node/element.rb', line 176 def find(*args) wait_until { super } end |
#first(*args) ⇒ Object
180 181 182 |
# File 'lib/capybara/node/element.rb', line 180 def first(*args) wait_until { super } end |
#inspect ⇒ Object
194 195 196 197 198 |
# File 'lib/capybara/node/element.rb', line 194 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.
35 36 37 |
# File 'lib/capybara/node/element.rb', line 35 def native wait_until { base.native } end |
#path ⇒ String
An XPath expression describing where on the page the element can be found
147 148 149 |
# File 'lib/capybara/node/element.rb', line 147 def path wait_until { base.path } end |
#reload ⇒ Object
188 189 190 191 192 |
# File 'lib/capybara/node/element.rb', line 188 def reload reloaded = parent.reload.first(@selector.name, @selector.locator, @selector.) @base = reloaded.base if reloaded self end |
#select_option ⇒ Object
Select this node if is an option element inside a select tag
82 83 84 |
# File 'lib/capybara/node/element.rb', line 82 def select_option wait_until { base.select_option } end |
#selected? ⇒ Boolean
Whether or not the element is selected.
137 138 139 |
# File 'lib/capybara/node/element.rb', line 137 def selected? wait_until { base.selected? } end |
#set(value) ⇒ Object
Set the value of the form element to the given value.
74 75 76 |
# File 'lib/capybara/node/element.rb', line 74 def set(value) wait_until { base.set(value) } end |
#tag_name ⇒ String
Returns The tag name of the element.
106 107 108 |
# File 'lib/capybara/node/element.rb', line 106 def tag_name wait_until { base.tag_name } end |
#text ⇒ String
Returns The text of the element.
43 44 45 |
# File 'lib/capybara/node/element.rb', line 43 def text wait_until { base.text } end |
#trigger(event) ⇒ Object
Trigger any event on the current element, for example mouseover or focus events. Does not work in Selenium.
158 159 160 |
# File 'lib/capybara/node/element.rb', line 158 def trigger(event) wait_until { base.trigger(event) } end |
#unselect_option ⇒ Object
Unselect this node if is an option element inside a multiple select tag
90 91 92 |
# File 'lib/capybara/node/element.rb', line 90 def unselect_option wait_until { base.unselect_option } end |
#value ⇒ String
Returns The value of the form element.
64 65 66 |
# File 'lib/capybara/node/element.rb', line 64 def value wait_until { base.value } end |
#visible? ⇒ Boolean
Whether or not the element is visible. Not all drivers support CSS, so the result may be inaccurate.
117 118 119 |
# File 'lib/capybara/node/element.rb', line 117 def visible? wait_until { base.visible? } end |