Class: Watir::Browser::Scroll

Inherits:
Object
  • Object
show all
Defined in:
lib/watir-scroll/browser/scroll.rb

Instance Method Summary collapse

Constructor Details

#initialize(browser) ⇒ Scroll

Returns a new instance of Scroll.



5
6
7
# File 'lib/watir-scroll/browser/scroll.rb', line 5

def initialize(browser)
  @browser = browser
end

Instance Method Details

#by(left, top) ⇒ Object

Scrolls by offset.

Parameters:

  • left (Fixnum)

    Horizontal offset

  • top (Fixnum)

    Vertical offset



36
37
38
39
# File 'lib/watir-scroll/browser/scroll.rb', line 36

def by(left, top)
  @browser.execute_script('window.scrollBy(arguments[0], arguments[1]);', Integer(left), Integer(top))
  self
end

#to(param) ⇒ Object

Scrolls to position.

Parameters:

  • param (Symbol, Array<Fixnum>)


13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/watir-scroll/browser/scroll.rb', line 13

def to(param)
  args = case param
         when :top, :start
           'window.scrollTo(0, 0);'
         when :center
           'window.scrollTo(window.outerWidth / 2, window.outerHeight / 2);'
         when :bottom, :end
           'window.scrollTo(0, document.body.scrollHeight);'
         when Array
           ['window.scrollTo(arguments[0], arguments[1]);', Integer(param[0]), Integer(param[1])]
         else
           raise ArgumentError, "Don't know how to scroll to: #{param}!"
         end
  @browser.execute_script(*args)

  self
end