Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

use center of elements when drag and dropping

  • Loading branch information...
commit dbe51436fb873677305ab60f9e74044aaa0a5159 1 parent 23fea95
Jarmo Pertman jarmo authored
Showing with 16 additions and 5 deletions.
  1. +16 −5 watir/lib/watir/drag_and_drop_helper.rb
21 watir/lib/watir/drag_and_drop_helper.rb
View
@@ -4,8 +4,7 @@ module DragAndDropHelper
def drag_and_drop_on(target)
perform_action do
assert_target target
- drop_x = target.send :left_edge_absolute
- drop_y = target.send :top_edge_absolute
+ drop_x, drop_y = target.send :source_x_y
drag_to drop_x, drop_y
end
end
@@ -22,14 +21,14 @@ def drag_and_drop_by(distance_x, distance_y)
def drag_to(drop_x, drop_y)
drag_x, drag_y = source_x_y
mouse = page_container.rautomation.mouse
- mouse.move :x => drag_x + 10, :y => drag_y + 10
+ mouse.move :x => drag_x , :y => drag_y
mouse.press
- mouse.move :x => drop_x + 10, :y => drop_y + 10
+ mouse.move :x => drop_x, :y => drop_y
mouse.release
end
def source_x_y
- return left_edge_absolute, top_edge_absolute
+ center_x_y_absolute left_edge_absolute, top_edge_absolute
end
def assert_target(target)
@@ -53,5 +52,17 @@ def left_edge_absolute
left_edge + page_container.document.parentWindow.screenLeft.to_i
end
+ def right_edge
+ ole_object.getBoundingClientRect.right.to_i
+ end
+
+ def bottom_edge
+ ole_object.getBoundingClientRect.bottom.to_i
+ end
+
+ def center_x_y_absolute x, y
+ return (right_edge - left_edge) / 2 + x, (bottom_edge - top_edge) / 2 + y
+ end
+
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.