Class: Capybara::Node::Element

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

Overview

Additional useful methods to extend the Capybara::Node::Element class with

Instance Method Summary collapse

Instance Method Details

#horizontal_positionInteger

The Left-Most pixel's horizontal position in the DOM (From element.rect)

Returns:

  • (Integer)


12
13
14
# File 'lib/automation_helpers/extensions/capybara/node/element.rb', line 12

def horizontal_position
  native.rect.x.to_i
end

#scroll_into_viewCapybara::Node::Element

Scrolls the element directly into view. Useful to mitigate vs stale element errors



26
27
28
29
30
31
32
# File 'lib/automation_helpers/extensions/capybara/node/element.rb', line 26

def scroll_into_view
  session.driver.browser.execute_script(
    "arguments[0].scrollIntoView({block: 'center', inline: 'nearest'});",
    native
  )
  self
end

#stale?Boolean

Whether the element is in a stale state or not

Returns:

  • (Boolean)


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

def stale?
  inspect == 'Obsolete #<Capybara::Node::Element>'
end

#vertical_positionInteger

The Left-Most pixel's vertical position in the DOM (From element.rect)

Returns:

  • (Integer)


19
20
21
# File 'lib/automation_helpers/extensions/capybara/node/element.rb', line 19

def vertical_position
  native.rect.y.to_i
end