Module: Capybara::Selenium::Scroll

Included in:
Node
Defined in:
lib/capybara/selenium/extensions/scroll.rb

Instance Method Summary collapse

Instance Method Details

#scroll_by(x, y) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/capybara/selenium/extensions/scroll.rb', line 6

def scroll_by(x, y)
  driver.execute_script <<~JS, self, x, y
    var el = arguments[0];
    if (el.scrollBy){
      el.scrollBy(arguments[1], arguments[2]);
    } else {
      el.scrollTop = el.scrollTop + arguments[2];
      el.scrollLeft = el.scrollLeft + arguments[1];
    }
  JS
end

#scroll_to(element, location, position = nil) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/capybara/selenium/extensions/scroll.rb', line 18

def scroll_to(element, location, position = nil)
  # location, element = element, nil if element.is_a? Symbol
  if element.is_a? Capybara::Selenium::Node
    scroll_element_to_location(element, location)
  elsif location.is_a? Symbol
    scroll_to_location(location)
  else
    scroll_to_coords(*position)
  end
  self
end