Skip to content

Commit

Permalink
Added support for drag and drop plus drag and drop by offset. fixes #60
Browse files Browse the repository at this point in the history
  • Loading branch information
j1z0 committed Jun 30, 2012
1 parent 70f8d6b commit 19b809b
Show file tree
Hide file tree
Showing 6 changed files with 559 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ Release Notes
Selenium Library.
[jouk0]

- Added drag and drop support with two functions `drag and drop source
target` and `drag and drop by offset source xoffset yoffset`
[mamathanag] and [j1z0]

1.0.1
-----
- Support for Robot Framework 2.7
Expand Down
31 changes: 30 additions & 1 deletion src/Selenium2Library/keywords/_element.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ def get_value(self, locator):
See `introduction` for details about locating elements.
"""
return self._get_value(locator)

def get_text(self, locator):
"""Returns the text value of element identified by `locator`.
Expand Down Expand Up @@ -275,6 +275,35 @@ def focus(self, locator):
element = self._element_find(locator, True, True)
self._current_browser().execute_script("arguments[0].focus();", element)

def drag_and_drop(self, source, target):
"""Drags element identified with `source` which is a locator.
Element can be moved on top of another element with `target`
argument.
`target` is a locator of the element where the dragged object is
dropped.
Examples:
| Drag And Drop | elem1 | elem2 | # Move elem1 over elem2. |
"""
src_elem = self._element_find(source,True,True)
trg_elem = self._element_find(target,True,True)
ActionChains(self._current_browser()).drag_and_drop(src_elem, trg_elem).perform()


def drag_and_drop_by_offset(self, source, xoffset, yoffset):
"""Drags element identified with `source` which is a locator.
Element will be moved by xoffset and yoffset. each of which is a
negative or positive number specify the offset.
Examples:
| Drag And Drop | myElem | 50 | -35 | # Move myElem 50px right and 35px down. |
"""
src_elem = self._element_find(source, True, True)
ActionChains(self._current_browser()).drag_and_drop_by_offset(src_elem, xoffset, yoffset).perform()

def mouse_down(self, locator):
"""Simulates pressing the left mouse button on the element specified by `locator`.
Expand Down
15 changes: 15 additions & 0 deletions test/acceptance/keywords/javascript.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,18 @@ Open Context Menu
Go To Page "javascript/context_menu.html"
Open Context Menu myDiv

Drag and Drop
[Setup] Go To Page "javascript/drag_and_drop.html"
Element Text Should Be id=droppable Drop here
Drag and Drop id=draggable id=droppable
Element Text Should Be id=droppable Dropped!

Drag and Drop by Offset
[Setup] Go To Page "javascript/drag_and_drop.html"
Element Text Should Be id=droppable Drop here
Drag and Drop by Offset id=draggable 1 1
Element Text Should Be id=droppable Drop here
Drag and Drop by Offset id=draggable 100 20
Element Text Should Be id=droppable Dropped!


39 changes: 39 additions & 0 deletions test/resources/html/javascript/drag_and_drop.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<!DOCTYPE html>
<html>
<head>
<script src="jquery.js" type="text/javascript"></script>
<script src="jquery-ui.min.js" type="text/javascript"></script>
<link href="jquery-ui.css" rel="stylesheet" type="text/css" />

<style>
#draggable { width: 100px; height: 100px; padding: 0.5em; float: left; margin: 10px 10px 10px 0; }
#droppable { width: 150px; height: 150px; padding: 0.5em; float: left; margin: 10px; }
</style>
<script>
$(function() {
$( "#draggable" ).draggable();
$( "#droppable" ).droppable({
drop: function( event, ui ) {
$( this )
.addClass( "ui-state-highlight" )
.find( "p" )
.html( "Dropped!" );
}
});
});
</script>
</head>
<body>
<div class="demo">
<div id="draggable" class="ui-widget-content">
<p>Drag me to my target</p>
</div>
<div id="droppable" class="ui-widget-header">
<p>Drop here</p>
</div>
</div>
<div class="demo-description" style="display: none; ">
<p>Enable any DOM element to be droppable, a target for draggable elements.</p>
</div>
</body>
</html>
Loading

0 comments on commit 19b809b

Please sign in to comment.