123456789_123456789_123456789_123456789_123456789_

Module: Selenium::WebDriver::WheelActions

Relationships & Source Files
Namespace Children
Classes:
Extension / Inclusion / Inheritance Descendants
Included In:
Defined in: rb/lib/selenium/webdriver/common/interactions/scroll_origin.rb,
rb/lib/selenium/webdriver/common/interactions/wheel_actions.rb

Instance Attribute Summary

Instance Method Summary

Instance Attribute Details

#default_scroll_duration (rw)

By default this is set to 250ms in the ActionBuilder constructor It can be overridden with default_scroll_duration=

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/common/interactions/wheel_actions.rb', line 30

def default_scroll_duration
  @default_scroll_duration ||= @duration / 1000.0 # convert ms to seconds
end

#default_scroll_duration=(value) (rw)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/common/interactions/wheel_actions.rb', line 23

attr_writer :default_scroll_duration

Instance Method Details

#scroll(**opts) (private)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/common/interactions/wheel_actions.rb', line 101

def scroll(**opts)
  opts[:duration] = default_scroll_duration
  wheel = wheel_input(opts.delete(:device))
  wheel.create_scroll(**opts)
  tick(wheel)
  self
end

#scroll_by(delta_x, delta_y, device: nil) ⇒ WheelActions

Scrolls by provided amounts with the origin in the top left corner of the viewport.

Examples:

Scroll viewport by a specified amount

el = driver.find_element(id: "some_id")
driver.action.scroll_by(100, 200).perform

Parameters:

  • delta_x (Integer)

    Distance along X axis to scroll using the wheel. A negative value scrolls left.

  • delta_y (Integer)

    Distance along Y axis to scroll using the wheel. A negative value scrolls up.

Returns:

  • (WheelActions)

    A self reference.

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/common/interactions/wheel_actions.rb', line 58

def scroll_by(delta_x, delta_y, device: nil)
  scroll(delta_x: delta_x, delta_y: delta_y, device: device)
end

#scroll_from(scroll_origin, delta_x, delta_y, device: nil) ⇒ WheelActions

Scrolls by provided amount based on a provided origin.

The scroll origin is either the center of an element or the upper left of the viewport plus any offsets. If the origin is an element, and the element is not in the viewport, the bottom of the element will first

be scrolled to the bottom of the viewport.

Examples:

Scroll from element by a specified amount

el = driver.find_element(id: "some_id")
origin = WheelActions::ScrollOrigin.element(el)
driver.action.scroll_from(origin, 0, 200).perform

Scroll from element by a specified amount with an offset

el = driver.find_element(id: "some_id")
origin = WheelActions::ScrollOrigin.element(el, 10, 10)
driver.action.scroll_from(origin, 100, 200).perform

Scroll viewport by a specified amount with an offset

origin = WheelActions::ScrollOrigin.viewport(10, 10)
driver.action.scroll_from(origin, 0, 200).perform

Parameters:

  • scroll_origin (ScrollOrigin)

    Where scroll originates (viewport or element center) plus provided offsets.

  • delta_x (Integer)

    Distance along X axis to scroll using the wheel. A negative value scrolls left.

  • delta_y (Integer)

    Distance along Y axis to scroll using the wheel. A negative value scrolls up.

Returns:

  • (WheelActions)

    A self reference.

Raises:

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/common/interactions/wheel_actions.rb', line 88

def scroll_from(scroll_origin, delta_x, delta_y, device: nil)
  raise TypeError, "#{scroll_origin.inspect} isn't a valid ScrollOrigin" unless scroll_origin.is_a?(ScrollOrigin)

  scroll(x: scroll_origin.x_offset,
         y: scroll_origin.y_offset,
         delta_x: delta_x,
         delta_y: delta_y,
         origin: scroll_origin.origin,
         device: device)
end

#scroll_to(element, device: nil) ⇒ WheelActions

If the element is outside the viewport, scrolls the bottom of the element to the bottom of the viewport.

Examples:

Scroll to element

el = driver.find_element(id: "some_id")
driver.action.scroll_to(element).perform

Parameters:

  • element (Object)

    Which element to scroll into the viewport.

  • device (Object)

    Which device to use to scroll

Returns:

  • (WheelActions)

    A self reference.

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/common/interactions/wheel_actions.rb', line 44

def scroll_to(element, device: nil)
  scroll(origin: element, device: device)
end

#wheel_input(name = nil) (private)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/common/interactions/wheel_actions.rb', line 109

def wheel_input(name = nil)
  device(name: name, type: Interactions::WHEEL) || add_wheel_input('wheel')
end