Method: Selenium::WebDriver::PointerActions#move_to

Defined in:
lib/selenium/webdriver/common/interactions/pointer_actions.rb

#move_to(element, right_by = nil, down_by = nil, **opts) ⇒ ActionBuilder

Moves the pointer to the in-view center point of the given element. Then the pointer is moved to optional offset coordinates.

The element is not scrolled into view. MoveTargetOutOfBoundsError will be raised if element with offset is outside the viewport

When using offsets, both coordinates need to be passed.

Examples:

Move the pointer to element


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

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

Parameters:

  • element (Selenium::WebDriver::Element)

    to move to.

  • right_by (Integer) (defaults to: nil)

    Optional offset from the in-view center of the element. A negative value means coordinates to the left of the center.

  • down_by (Integer) (defaults to: nil)

    Optional offset from the in-view center of the element. A negative value means coordinates to the top of the center.

Returns:



97
98
99
100
101
102
103
104
105
106
# File 'lib/selenium/webdriver/common/interactions/pointer_actions.rb', line 97

def move_to(element, right_by = nil, down_by = nil, **opts)
  pointer = pointer_input(opts.delete(:device))
  pointer.create_pointer_move(duration: opts.delete(:duration) || default_move_duration,
                              x: right_by || 0,
                              y: down_by || 0,
                              origin: element,
                              **opts)
  tick(pointer)
  self
end