Class: Watir::Scroll

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

Instance Method Summary collapse

Constructor Details

#initialize(object) ⇒ Scroll

Returns a new instance of Scroll.


9
10
11
# File 'lib/watir/scroll.rb', line 9

def initialize(object)
  @object = object
end

Instance Method Details

#by(left, top) ⇒ Object

Scrolls by offset.

Parameters:

  • left (Fixnum)

    Horizontal offset

  • top (Fixnum)

    Vertical offset


17
18
19
20
# File 'lib/watir/scroll.rb', line 17

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

#to(param = :top) ⇒ Object

Scrolls to specified location.

Parameters:

  • param (Symbol) (defaults to: :top)

Raises:

  • (ArgumentError)

26
27
28
29
30
31
32
# File 'lib/watir/scroll.rb', line 26

def to(param = :top)
  args = @object.is_a?(Watir::Element) ? element_scroll(param) : browser_scroll(param)
  raise ArgumentError, "Don't know how to scroll #{@object} to: #{param}!" if args.nil?

  @object.browser.execute_script(*args)
  self
end