Module: Watir::DragAndDropHelper

Included in:
Element
Defined in:
lib/watir-classic/drag_and_drop_helper.rb

Overview

This module has methods for performing drag & drop functionality. It is included into Element making each element draggable if they’re draggable on the web page too.

Instance Method Summary collapse

Instance Method Details

#drag_and_drop_by(distance_x, distance_y) ⇒ Object

Drag and drop this element by a distance.

Parameters:

  • distance_x (Fixnum)

    distance to drag element on x-axis. Can be negative.

  • distance_y (Fixnum)

    distance to drag element on y-axis. Can be negative.

Raises:



29
30
31
32
33
34
35
36
37
38
# File 'lib/watir-classic/drag_and_drop_helper.rb', line 29

def drag_and_drop_by(distance_x, distance_y)
  perform_action do
    drag_to do |mouse|
      drag_x, drag_y = source_x_y
      ole_object.document.parentWindow.scrollTo(drag_x + distance_x, drag_y + distance_y)
      drag_x, drag_y = source_x_y
      mouse.move :x => drag_x + distance_x, :y => drag_y + distance_y
    end
  end
end

#drag_and_drop_on(target) ⇒ Object

Drag and drop this element onto another element.

Parameters:

  • target (Element)

    element to be dragged on.

Raises:



12
13
14
15
16
17
18
19
20
21
# File 'lib/watir-classic/drag_and_drop_helper.rb', line 12

def drag_and_drop_on(target)
  perform_action do
    assert_target target
    drag_to do |mouse|
      ole_object.document.parentWindow.scrollTo(*target.send(:source_x_y_relative))
      drop_x, drop_y = target.send(:source_x_y)
      mouse.move :x => drop_x, :y => drop_y
    end
  end
end