Skip to content

Instantly share code, notes, and snippets.

@jenniferlianne
Created March 4, 2014 19:12
Show Gist options
  • Save jenniferlianne/9353489 to your computer and use it in GitHub Desktop.
Save jenniferlianne/9353489 to your computer and use it in GitHub Desktop.
Selenium Webdriver Can't Drag and Drop Events
!DOCTYPE html>
<html lang='en'>
<head>
<meta charset="utf-8" />
<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/themes/smoothness/jquery-ui.css" />
<link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" />
<link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/fullcalendar/1.6.4/fullcalendar.css" />
<style>
.external-event{margin:6px 0;color:#FFF;background-color:#abbac3;font-size:13px;line-height:28px}
</style>
</head>
<body>
<div class="row calendar-container">
<div class="col-sm-9">
<div class='calendar-div'></div>
</div>
<div class="col-sm-3">
<h4>Events with no date</h4>
<div class="external_event_list">
<div id='evt1' class="external-event" data-class="label-yellow">
<i class="icon-move"></i>
This event can be dragged.
</div>
</div>
</div>
</div>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/fullcalendar/1.6.4/fullcalendar.min.js"></script>
<script>
function makeCalendar( calendar_div )
{
var calendar = calendar_div.fullCalendar({
buttonText: {
prev: '<i class="icon-chevron-left"></i>',
next: '<i class="icon-chevron-right"></i>'
},
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
editable: true,
droppable: true, // this allows things to be dropped onto the calendar !!!
drop: function(date, allDay) { // this function is called when something is dropped
// retrieve the dropped element's stored Event Object
var originalEventObject = $(this).data('eventObject');
var $extraEventClass = $(this).attr('data-class');
// we need to copy it, so that multiple events don't have a reference to the same object
var copiedEventObject = $.extend({}, originalEventObject);
// assign it the date that was reported
copiedEventObject.start = date;
copiedEventObject.allDay = allDay;
if($extraEventClass) copiedEventObject['className'] = [$extraEventClass];
// render the event on the calendar
// the last `true` argument determines if the event "sticks" (http://arshaw.com/fullcalendar/docs/event_rendering/renderEvent/)
calendar_div.fullCalendar('renderEvent', copiedEventObject);
// remove the element from the "Draggable Events" list
$(this).remove();
},
});
}
jQuery(function($) {
$('.calendar-div').each(function() {
makeCalendar($(this));
});
$('div.external-event').each(function() {
// create an Event Object (http://arshaw.com/fullcalendar/docs/event_data/Event_Object/)
// it doesn't need to have a start or end
var eventObject = {
title: $.trim($(this).text()), // use the element's text as the event title
};
// store the Event Object in the DOM element so we can get to it later
$(this).data('eventObject', eventObject);
// make the event draggable using jQuery UI
$(this).draggable({
zIndex: 999,
revert: true, // will cause the event to go back to its
revertDuration: 0 // original position after the drag
});
});
})
</script>
</body>
</html>
import time
import os
import datetime
import unittest
from selenium.webdriver.firefox.webdriver import WebDriver
from selenium.webdriver.common.action_chains import ActionChains
class FullCalTestCase(unittest.TestCase):
@classmethod
def setUpClass(cls):
super(FullCalTestCase, cls).setUpClass()
cls.sel = WebDriver()
@classmethod
def tearDownClass(cls):
super(FullCalTestCase, cls).tearDownClass()
cls.sel.quit()
def test_fullcal(self):
# move event to the 24th of the month
localdir = os.path.dirname(os.path.abspath(__file__))
self.sel.get('file://%s/fullcaltest.html' % localdir)
today = datetime.date.today()
time.sleep(5)
move_to_date = datetime.date(today.year, today.month, 24)
evt = self.sel.find_element_by_css_selector('#evt1')
cal_square = self.sel.find_element_by_css_selector('td[data-date=\'%s\']' % move_to_date.isoformat())
ActionChains(self.sel).click_and_hold(evt).move_to_element(cal_square).perform()
time.sleep(10)
ActionChains(self.sel).release().perform()
time.sleep(5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment