2
2
import time
3
3
4
4
from selenium .webdriver .common .action_chains import ActionChains
5
+ from selenium .webdriver .common .by import By
5
6
6
7
from .utils import xpath_cls , xpath_item , is_integer , Position , Size , ElementRect
7
8
@@ -107,7 +108,7 @@ def source(self):
107
108
"*[%s]" % xpath_cls ("djn-drag-handler" ),
108
109
]
109
110
)
110
- self ._source = source_item .find_element_by_xpath ( drag_handler_xpath )
111
+ self ._source = source_item .find_element ( By . XPATH , drag_handler_xpath )
111
112
return self ._source
112
113
113
114
@property
@@ -127,7 +128,7 @@ def target(self):
127
128
"item_pred" : xpath_item (),
128
129
"item_pos" : self .to_indexes [- 1 ][1 ] + 1 ,
129
130
}
130
- self ._target = target_inline_parent .find_element_by_xpath ( target_xpath )
131
+ self ._target = target_inline_parent .find_element ( By . XPATH , target_xpath )
131
132
return self ._target
132
133
133
134
def initialize_drag (self ):
@@ -140,6 +141,10 @@ def initialize_drag(self):
140
141
document.documentElement.scrollTop += (top - 16);
141
142
} else {
142
143
el.scrollIntoView();
144
+ top = el.getBoundingClientRect().top;
145
+ if (top <= 15) {
146
+ document.documentElement.scrollTop += (top - 16);
147
+ }
143
148
}
144
149
""" ,
145
150
source ,
@@ -148,15 +153,15 @@ def initialize_drag(self):
148
153
149
154
(
150
155
ActionChains (self .selenium )
151
- .move_to_element_with_offset (source , 5 , 5 )
156
+ .move_to_element_with_offset (source , 3 , 3 )
152
157
.click_and_hold ()
153
158
.perform ()
154
159
)
155
160
156
161
time .sleep (0.05 )
157
- ActionChains (self .selenium ).move_by_offset (0 , - 15 ).perform ()
162
+ ActionChains (self .selenium ).move_by_offset (0 , - 10 ).perform ()
158
163
time .sleep (0.05 )
159
- ActionChains (self .selenium ).move_by_offset (0 , 15 ).perform ()
164
+ ActionChains (self .selenium ).move_by_offset (0 , 10 ).perform ()
160
165
161
166
with self .test_case .visible_selector (".ui-sortable-helper" ) as el :
162
167
return el
@@ -189,7 +194,7 @@ def _match_helper_with_target(self, helper_element, target_element):
189
194
15 , min (viewport_height // 3 , (2 * inline_height ) // 3 , abs (dy ) // 2 )
190
195
)
191
196
192
- max_iter = 50
197
+ max_iter = 120
193
198
i = 0
194
199
prev_pos_diff = None
195
200
direction = None
@@ -220,9 +225,9 @@ def _match_helper_with_target(self, helper_element, target_element):
220
225
if flip_count > 3 :
221
226
increment = 10
222
227
elif flip_count > 5 :
223
- increment = 5
228
+ increment = 2
224
229
else :
225
- increment = max (abs (dy // 2 ), flip_count * flip_multiplier )
230
+ increment = min (abs (dy // 2 ), flip_count * flip_multiplier )
226
231
direction_flip *= - 1
227
232
direction = pos_diff * direction_flip
228
233
inc = increment * direction
@@ -252,7 +257,7 @@ def _num_preceding_siblings(self, ctx, condition):
252
257
is extraordinarily slow. So we just grab all siblings and iterate
253
258
through the elements in python.
254
259
"""
255
- siblings = ctx .find_element_by_xpath ( "parent::*" ).find_elements_by_xpath ( "*" )
260
+ siblings = ctx .find_element ( By . XPATH , "parent::*" ).find_elements ( By . XPATH , "*" )
256
261
count = 0
257
262
for el in siblings :
258
263
if el .id == ctx .id :
@@ -278,8 +283,8 @@ def is_djn_group(el):
278
283
279
284
@property
280
285
def current_position (self ):
281
- placeholder = self .selenium .find_element_by_css_selector (
282
- ".ui-sortable-placeholder"
286
+ placeholder = self .selenium .find_element (
287
+ By . CSS_SELECTOR , ".ui-sortable-placeholder"
283
288
)
284
289
pos = []
285
290
ctx = None
@@ -288,10 +293,10 @@ def current_position(self):
288
293
if ctx is None :
289
294
ctx = placeholder
290
295
else :
291
- ctx = ctx .find_element_by_xpath ( ancestor_xpath )
296
+ ctx = ctx .find_element ( By . XPATH , ancestor_xpath )
292
297
item_index = self ._num_preceding_djn_items (ctx )
293
- ctx = ctx .find_element_by_xpath (
294
- "ancestor::*[%s][1]" % xpath_cls ("djn-group" )
298
+ ctx = ctx .find_element (
299
+ By . XPATH , "ancestor::*[%s][1]" % xpath_cls ("djn-group" )
295
300
)
296
301
inline_index = self ._num_preceding_djn_groups (ctx )
297
302
pos .insert (0 , (inline_index , item_index ))
0 commit comments