Class: Watir::Browser::Scroll

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

Constant Summary collapse

VERSION =
"0.2.0"

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

#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
# 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)
end