class Capybara::Node::Element
@see Capybara::Node
bar[:title]
bar.text
bar.value
element:
{Capybara::Node::Element} also has access to HTML attributes and other properties of the
bar.select(‘Baz’, from: ‘Quox’) # from Capybara::Node::Actions
bar = session.find(‘#bar’) # from Capybara::Node::Finders
session = Capybara::Session.new(:rack_test, my_app)
to interact with the contents of this element the same as with a document:
A {Capybara::Node::Element} represents a single element on the page. It is possible
#
def [](attribute)
-
(String)- The value of the attribute
Parameters:
-
attribute(Symbol) -- The attribute to retrieve
def [](attribute) synchronize { base[attribute] } end
def allow_reload!
def allow_reload! @allow_reload = true end
def checked?
-
(Boolean)- Whether the element is checked
def checked? synchronize { base.checked? } end
def click(*keys, **offset)
-
(Capybara::Node::Element)- The element
Parameters:
-
offset(Hash) -- x and y coordinates to offset the click location from the top left corner of the element. If not specified will click the middle of the element. -
*key_modifiers(Array<:alt, :control, :meta, :shift>) -- Keys to be held down when clicking
Overloads:
-
click(*key_modifiers=[], offset={x: nil, y: nil})
def click(*keys, **offset) synchronize { base.click(keys, offset) } self end
def disabled?
-
(Boolean)- Whether the element is disabled
def disabled? synchronize { base.disabled? } end
def double_click(*keys, **offset)
-
(Capybara::Node::Element)- The element
def double_click(*keys, **offset) synchronize { base.double_click(keys, offset) } self end
def drag_to(node)
-
(Capybara::Node::Element)- The element
Parameters:
-
node(Capybara::Node::Element) -- The element to drag to
def drag_to(node) synchronize { base.drag_to(node.base) } self end
def hover
-
(Capybara::Node::Element)- The element
def hover synchronize { base.hover } self end
def initialize(session, base, query_scope, query)
def initialize(session, base, query_scope, query) super(session, base) @query_scope = query_scope @query = query @allow_reload = false end
def inspect
def inspect %(#<Capybara::Node::Element tag="#{base.tag_name}" path="#{base.path}">) rescue NotSupportedByDriverError %(#<Capybara::Node::Element tag="#{base.tag_name}">) rescue => e raise unless session.driver.invalid_element_errors.any? { |et| e.is_a?(et) } %(Obsolete #<Capybara::Node::Element>) end
def multiple?
-
(Boolean)- Whether the element supports multiple results.
def multiple? synchronize { base.multiple? } end
def native
-
(Object)- The native element from the driver, this allows access to driver specific methods
def native synchronize { base.native } end
def path
-
(String)- An XPath expression
def path synchronize { base.path } end
def readonly?
-
(Boolean)- Whether the element is readonly
def readonly? synchronize { base.readonly? } end
def reload
def reload if @allow_reload begin reloaded = query_scope.reload.first(@query.name, @query.locator, @query.options) @base = reloaded.base if reloaded rescue => e raise e unless catch_error?(e) end end self end
def right_click(*keys, **offset)
-
(Capybara::Node::Element)- The element
def right_click(*keys, **offset) synchronize { base.right_click(keys, offset) } self end
def select_option
-
(Capybara::Node::Element)- The element
def select_option warn "Attempt to select disabled option: #{value || text}" if disabled? synchronize { base.select_option } self end
def selected?
-
(Boolean)- Whether the element is selected
def selected? synchronize { base.selected? } end
def send_keys(*args)
-
(Capybara::Node::Element)- The element
Parameters:
-
keys(String, Symbol, Array) --
Overloads:
-
send_keys(keys, ...)
def send_keys(*args) synchronize { base.send_keys(*args) } self end
def set(value, **options)
-
(Capybara::Node::Element)- The element
Parameters:
-
options(Hash{}) -- Driver specific options for how to set the value -
value(String) -- The new value
def set(value, **options) raise Capybara::ReadOnlyElementError, "Attempt to set readonly element with value: #{value}" if readonly? synchronize { base.set(value, options) } self end
def tag_name
-
(String)- The tag name of the element
def tag_name synchronize { base.tag_name } end
def text(type = nil)
-
(String)- The text of the element
Parameters:
-
type(:all, :visible) -- Whether to return only visible or all text
def text(type = nil) type ||= :all unless session_options.ignore_hidden_elements or session_options.visible_text_only synchronize do if type == :all base.all_text else base.visible_text end end end
def trigger(event)
-
(Capybara::Node::Element)- The element
Parameters:
-
event(String) -- The name of the event to trigger
def trigger(event) synchronize { base.trigger(event) } self end
def unselect_option
-
(Capybara::Node::Element)- The element
def unselect_option synchronize { base.unselect_option } self end
def value
-
(String)- The value of the form element
def value synchronize { base.value } end
def visible?
-
(Boolean)- Whether the element is visible
def visible? synchronize { base.visible? } end