@@ -151,8 +151,10 @@ def raise_unable_to_load_jquery_exception(driver):
151151
152152
153153def activate_jquery (driver ):
154- """If "jQuery is not defined", use this method to activate it for use.
155- This happens because jQuery is not always defined on web sites."""
154+ """
155+ If "jQuery is not defined" on a website, use this method to activate it.
156+ This method is needed because jQuery is not always defined on web sites.
157+ """
156158 try :
157159 # Let's first find out if jQuery is already defined.
158160 driver .execute_script ("jQuery('html');" )
@@ -163,20 +165,15 @@ def activate_jquery(driver):
163165 pass
164166 jquery_js = constants .JQuery .MIN_JS
165167 add_js_link (driver , jquery_js )
166- for x in range (25 ):
168+ for x in range (27 ):
167169 # jQuery needs a small amount of time to activate.
168170 try :
169171 driver .execute_script ("jQuery('html');" )
170172 return
171173 except Exception :
174+ if x == 15 :
175+ add_js_link (driver , jquery_js )
172176 time .sleep (0.1 )
173- try :
174- add_js_link (driver , jquery_js )
175- time .sleep (0.5 )
176- driver .execute_script ("jQuery('head');" )
177- return
178- except Exception :
179- pass
180177 # Since jQuery still isn't activating, give up and raise an exception
181178 raise_unable_to_load_jquery_exception (driver )
182179
@@ -1021,6 +1018,8 @@ def slow_scroll_to_element(driver, element, browser):
10211018
10221019
10231020def get_drag_and_drop_script ():
1021+ # This script uses jQuery to perform a Drag-and-Drop action.
1022+ # (Requires the Drag-selector and the Drop-selector to work)
10241023 script = r"""(function( $ ) {
10251024 $.fn.simulateDragDrop = function(options) {
10261025 return this.each(function() {
@@ -1078,7 +1077,57 @@ def get_drag_and_drop_script():
10781077 return script
10791078
10801079
1080+ def get_js_drag_and_drop_script ():
1081+ # HTML5 Drag-and-Drop script (Requires extra parameters to work)
1082+ # param1 (WebElement): Source element to drag
1083+ # param2 (WebElement): Target element for the drop (Optional)
1084+ # param3 (int): Optional - Drop offset x relative to the target
1085+ # param4 (int): Optional - Drop offset y relative to the target
1086+ # param4 (int): Optional - Delay in milliseconds (default = 1ms)
1087+ # param5 (string): Optional - Key pressed (ALT or CTRL or SHIFT)
1088+ script = """var t=arguments,e=t[0],n=t[1],i=t[2]||0,o=t[3]||0,r=t[4]||1,
1089+ a=t[5]||'',s='alt'===a||'\ue00a '===a,l='ctrl'===a||'\ue009 '===a,
1090+ c='shift'===a||'\ue008 '===a,u=e.ownerDocument,
1091+ f=e.getBoundingClientRect(),g=n?n.getBoundingClientRect():f,
1092+ p=f.left+f.width/2,d=f.top+f.height/2,h=g.left+(i||g.width/2),
1093+ m=g.top+(o||g.height/2),v=u.elementFromPoint(p,d),
1094+ y=u.elementFromPoint(h,m);if(!v||!y){
1095+ var E=new Error('source or target element is not interactable');
1096+ throw E.code=15,E}var _={constructor:DataTransfer,effectAllowed:null,
1097+ dropEffect:null,types:[],files:Object.setPrototypeOf([],null),
1098+ _items:Object.setPrototypeOf([],{add:function(t,e){
1099+ this[this.length]={_data:''+t,kind:'string',
1100+ type:e,getAsFile:function(){},getAsString:function(t){t(this._data)}},
1101+ _.types.push(e)},remove:function(t){
1102+ Array.prototype.splice.call(this,65535&t,1),_.types.splice(65535&t,1)},
1103+ clear:function(t,e){this.length=0,_.types.length=0}}),
1104+ setData:function(t,e){this.clearData(t),this._items.add(e,t)},
1105+ getData:function(t){for(var e=this._items.length;
1106+ e--&&this._items[e].type!==t;);return e>=0?this._items[e]._data:null},
1107+ clearData:function(t){for(var e=this._items.length;
1108+ e--&&this._items[e].type!==t;);this._items.remove(e)},
1109+ setDragImage:function(t){}};function w(t,e,n,i){
1110+ for(var o=0;o<e.length;++o){var r=u.createEvent('MouseEvent');
1111+ r.initMouseEvent(e[o],!0,!0,u.defaultView,0,0,0,p,d,l,s,c,!1,0,null),
1112+ t.dispatchEvent(r)}i&&setTimeout(i,n)}function D(t,e,n,i){
1113+ var o=u.createEvent('DragEvent');o.initMouseEvent(
1114+ e,!0,!0,u.defaultView,0,0,0,p,d,l,s,c,!1,0,null),Object.setPrototypeOf(
1115+ o,null),o.dataTransfer=_,Object.setPrototypeOf(o,DragEvent.prototype),
1116+ t.dispatchEvent(o),i&&setTimeout(i,n)}
1117+ 'items'in DataTransfer.prototype&&(_.items=_._items),
1118+ w(v,['pointerdown','mousedown'],1,function(){
1119+ for(var t=v;t&&!t.draggable;)t=t.parentElement;if(t&&t.contains(v)){
1120+ var e=y.getBoundingClientRect();D(v,'dragstart',r,function(){
1121+ var t=y.getBoundingClientRect();p=t.left+h-e.left,d=t.top+m-e.top,D(
1122+ y,'dragenter',1,function(){D(y,'dragover',r,
1123+ function(){D(u.elementFromPoint(p,d),'drop',1,function(){D(v,'dragend',
1124+ 1,function(){w(u.elementFromPoint(p,d),
1125+ ['mouseup','pointerup'])})})})})})}})"""
1126+ return script
1127+
1128+
10811129def get_drag_and_drop_with_offset_script (selector , x , y ):
1130+ # This script uses pure JS (No jQuery)
10821131 script_a = """
10831132 var source = document.querySelector("%s");
10841133 var offsetX = %f;
0 commit comments