@@ -4910,7 +4910,7 @@ def drag_and_drop(dataset):
49104910 elif left .strip ().lower () == "destination offset" and mid .strip ().lower () == 'optional parameter' :
49114911 destination_offset = right
49124912 elif left .strip ().lower () == "delay" :
4913- delay = int (right .strip ())
4913+ delay = float (right .strip ())
49144914
49154915 if not source :
49164916 CommonUtil .ExecLog (sModuleInfo , 'Please provide source element with "src element parameter", "src parent parameter" etc. Example:\n ' +
@@ -4932,59 +4932,67 @@ def drag_and_drop(dataset):
49324932 CommonUtil .ExecLog (sModuleInfo , "Destination Element is not found" , 3 )
49334933 return "zeuz_failed"
49344934
4935- if delay :
4936- if destination_offset :
4937- destination_x , destination_y = get_offsets (destination_offset , destination_element )
4938- else :
4939- destination_x = destination_element .location ['x' ]
4940- destination_y = destination_element .location ['y' ]
4941- distance_x = destination_x - source_element .location ['x' ]
4942- distance_y = destination_y - source_element .location ['y' ]
4943- total_time = delay
4944- total_distance = (distance_x ** 2 + distance_y ** 2 )** 0.5
4945-
4946- pixels_per_step = 5
4947- steps = int (total_distance / pixels_per_step )
4948-
4949- # Calculate the ideal time per step to fit within the total time
4950- ideal_time_per_step = total_time / steps
4951-
4952- # Start the high-resolution timer
4953- start_time = time .perf_counter ()
4954-
4955- # Create an ActionChains object
4956- actions = ActionChains (selenium_driver )
4957-
4958- # Click and hold the source element
4959- actions .click_and_hold (source_element ).perform ()
4960-
4961- # Manually move the mouse to the target element in small increments
4962- for i in range (steps ):
4963- # Calculate the movement for this step
4964- move_x = distance_x / steps
4965- move_y = distance_y / steps
4966-
4967- # Move the mouse by the calculated offset
4968- actions .move_by_offset (move_x , move_y ).perform ()
4969-
4970- # Calculate elapsed time and adjust the sleep time
4971- elapsed_time = time .perf_counter () - start_time
4972- remaining_time = total_time - elapsed_time
4973- time_per_step = remaining_time / (steps - i )
4974-
4975- if time_per_step > 0 :
4976- time .sleep (time_per_step )
4977-
4978- # Release the mouse button to drop the element
4979- actions .release ().perform ()
4980- sleep (2 )
4935+ """ The following code does not work with mentioned delay time. delay=2 takes 25 seconds for a dnd """
4936+ # if delay:
4937+ # if destination_offset:
4938+ # destination_x, destination_y = get_offsets(destination_offset, destination_element)
4939+ # else:
4940+ # destination_x = destination_element.location['x']
4941+ # destination_y = destination_element.location['y']
4942+ # distance_x = destination_x - source_element.location['x']
4943+ # distance_y = destination_y - source_element.location['y']
4944+ # total_time = delay
4945+ # total_distance = (distance_x**2 + distance_y**2)**0.5
4946+ #
4947+ # pixels_per_step = 5
4948+ # steps = int(total_distance / pixels_per_step)
4949+ #
4950+ # # Calculate the ideal time per step to fit within the total time
4951+ # ideal_time_per_step = total_time / steps
4952+ #
4953+ # # Start the high-resolution timer
4954+ # start_time = time.perf_counter()
4955+ #
4956+ # # Create an ActionChains object
4957+ # actions = ActionChains(selenium_driver)
4958+ #
4959+ # # Click and hold the source element
4960+ # actions.click_and_hold(source_element).perform()
4961+ #
4962+ # # Manually move the mouse to the target element in small increments
4963+ # for i in range(steps):
4964+ # # Calculate the movement for this step
4965+ # move_x = distance_x / steps
4966+ # move_y = distance_y / steps
4967+ #
4968+ # # Move the mouse by the calculated offset
4969+ # actions.move_by_offset(move_x, move_y).perform()
4970+ #
4971+ # # Calculate elapsed time and adjust the sleep time
4972+ # elapsed_time = time.perf_counter() - start_time
4973+ # remaining_time = total_time - elapsed_time
4974+ # time_per_step = remaining_time / (steps - i)
4975+ #
4976+ # if time_per_step > 0:
4977+ # time.sleep(time_per_step)
4978+ #
4979+ # # Release the mouse button to drop the element
4980+ # actions.release().perform()
4981+ # sleep(2)
49814982
4982- elif destination_offset :
4983+ if destination_offset :
49834984 x , y = get_offsets (destination_offset , destination_element )
4984- ActionChains (selenium_driver ).click_and_hold (source_element ).move_to_element_with_offset (destination_element , x , y ).release ().perform ()
4985+ if delay :
4986+ """ This line of code was not tested, just keeping here"""
4987+ ActionChains (selenium_driver ).click_and_hold (source_element ).move_to_element_with_offset (destination_element , x , y ).pause (0.5 ).release ().perform ()
4988+ else :
4989+ ActionChains (selenium_driver ).click_and_hold (source_element ).move_to_element_with_offset (destination_element , x , y ).release ().perform ()
4990+
49854991 else :
4986- ActionChains (selenium_driver ).drag_and_drop (source_element , destination_element ).perform ()
4987- # ActionChains(selenium_driver).click_and_hold(source_element).move_to_element(destination_element).pause(0.5).release(destination_element).perform()
4992+ if delay :
4993+ ActionChains (selenium_driver ).click_and_hold (source_element ).move_to_element (destination_element ).pause (0.5 ).release (destination_element ).perform ()
4994+ else :
4995+ ActionChains (selenium_driver ).drag_and_drop (source_element , destination_element ).perform ()
49884996
49894997 CommonUtil .ExecLog (sModuleInfo , "Drag and drop completed from source to destination" , 1 )
49904998 return "passed"
0 commit comments