Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Element#drag_and_drop_on works also with elements not in the viewport.

  • Loading branch information...
commit 50aeb1542f19af53263000c6e6ed984974a17b18 1 parent 3da28f2
Jarmo Pertman jarmo authored
Showing with 19 additions and 7 deletions.
  1. +18 −6 lib/watir-classic/drag_and_drop_helper.rb
  2. +1 −1  spec/watirspec
24 lib/watir-classic/drag_and_drop_helper.rb
View
@@ -4,26 +4,34 @@ module DragAndDropHelper
def drag_and_drop_on(target)
perform_action do
assert_target target
- drop_x, drop_y = target.send :source_x_y
- drag_to drop_x, drop_y
+ 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
def drag_and_drop_by(distance_x, distance_y)
perform_action do
- drag_x, drag_y = source_x_y
- drag_to drag_x + distance_x, drag_y + distance_y
+ 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
private
- def drag_to(drop_x, drop_y)
+ def drag_to
+ ole_object.document.parentWindow.scrollTo(*source_x_y_relative)
drag_x, drag_y = source_x_y
mouse = page_container.rautomation.mouse
mouse.move :x => drag_x , :y => drag_y
mouse.press
- mouse.move :x => drop_x, :y => drop_y
+ yield mouse
mouse.release
end
@@ -31,6 +39,10 @@ def source_x_y
center_x_y_absolute left_edge_absolute, top_edge_absolute
end
+ def source_x_y_relative
+ center_x_y_absolute left_edge, top_edge
+ end
+
def assert_target(target)
target.assert_exists
target.assert_enabled
2  spec/watirspec
@@ -1 +1 @@
-Subproject commit 831ceabab70c0bb1669d74e2114ee4ce5ff93afa
+Subproject commit 99a8eec4659ac7fadfa8244f0db902e8f920b9de
Please sign in to comment.
Something went wrong with that request. Please try again.