MCPcopy Create free account
hub / github.com/seleniumbase/SeleniumBase / gui_drag_drop_points

Method gui_drag_drop_points

seleniumbase/core/sb_cdp.py:2651–2688  ·  view source on GitHub ↗

Use PyAutoGUI to drag-and-drop from one point to another. Can simulate click-and-hold when using the same point twice.

(self, x1, y1, x2, y2, timeframe=0.35)

Source from the content-addressed store, hash-verified

2649 pyautogui.dragTo(x2, y2, button="left", duration=timeframe)
2650
2651 def gui_drag_drop_points(self, x1, y1, x2, y2, timeframe=0.35):
2652 """Use PyAutoGUI to drag-and-drop from one point to another.
2653 Can simulate click-and-hold when using the same point twice."""
2654 gui_lock = FileLock(constants.MultiBrowser.PYAUTOGUILOCK)
2655 with gui_lock: # Prevent issues with multiple processes
2656 self.__install_pyautogui_if_missing()
2657 import pyautogui
2658 pyautogui = self.__get_configured_pyautogui(pyautogui)
2659 width_ratio = 1.0
2660 if shared_utils.is_windows():
2661 window_rect = self.get_window_rect()
2662 width = window_rect["width"]
2663 height = window_rect["height"]
2664 win_x = window_rect["x"]
2665 win_y = window_rect["y"]
2666 scr_width = pyautogui.size().width
2667 win_width = self.evaluate("screen.availWidth;")
2668 width_ratio = round(float(scr_width) / float(win_width), 2)
2669 width_ratio += 0.01
2670 if width_ratio < 0.45 or width_ratio > 2.55:
2671 width_ratio = 1.01
2672 sb_config._saved_width_ratio = width_ratio
2673 with suppress(Exception):
2674 self.get_window() # If this fails, skip the rest
2675 self.minimize()
2676 self.__add_light_pause()
2677 self.__set_window_rect(win_x, win_y, width, height)
2678 self.__add_light_pause()
2679 x1 = x1 * width_ratio
2680 y1 = y1 * (width_ratio - 0.02)
2681 x2 = x2 * width_ratio
2682 y2 = y2 * (width_ratio - 0.02)
2683 self.bring_active_window_to_front()
2684 self.__gui_drag_drop(
2685 x1, y1, x2, y2, timeframe=timeframe, uc_lock=False
2686 )
2687 self.__slow_mode_pause_if_set()
2688 self.loop.run_until_complete(self.page.wait(0.2))
2689
2690 def gui_drag_and_drop(self, drag_selector, drop_selector, timeframe=0.35):
2691 """Use PyAutoGUI to drag-and-drop from one selector to another.

Callers 4

gui_drag_and_dropMethod · 0.95
gui_click_and_holdMethod · 0.95

Calls 12

get_window_rectMethod · 0.95
evaluateMethod · 0.95
get_windowMethod · 0.95
minimizeMethod · 0.95
__add_light_pauseMethod · 0.95
__set_window_rectMethod · 0.95
__gui_drag_dropMethod · 0.95
waitMethod · 0.45

Tested by

no test coverage detected