Skip to content

Commit b9a89f7

Browse files
authored
Merge pull request #3668 from seleniumbase/gui-click-and-hold
Add `sb.cdp.gui_click_and_hold(selector, timeframe)`
2 parents 990701d + 4fa959b commit b9a89f7

File tree

6 files changed

+30
-12
lines changed

6 files changed

+30
-12
lines changed

examples/cdp_mode/ReadMe.md

+1
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,7 @@ sb.cdp.gui_click_x_y(x, y)
467467
sb.cdp.gui_click_element(selector)
468468
sb.cdp.gui_drag_drop_points(x1, y1, x2, y2, timeframe=0.35)
469469
sb.cdp.gui_drag_and_drop(drag_selector, drop_selector, timeframe=0.35)
470+
sb.cdp.gui_click_and_hold(selector, timeframe=0.35)
470471
sb.cdp.gui_hover_x_y(x, y)
471472
sb.cdp.gui_hover_element(selector)
472473
sb.cdp.gui_hover_and_click(hover_selector, click_selector)

requirements.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ mycdp>=1.1.1
1515
pynose>=1.5.4
1616
platformdirs>=4.3.6;python_version<"3.9"
1717
platformdirs>=4.3.7;python_version>="3.9"
18-
typing-extensions>=4.13.1
18+
typing-extensions>=4.13.2
1919
sbvirtualdisplay>=1.4.0
2020
MarkupSafe==2.1.5;python_version<"3.9"
2121
MarkupSafe>=3.0.2;python_version>="3.9"
@@ -33,7 +33,7 @@ idna==3.10
3333
chardet==5.2.0
3434
charset-normalizer==3.4.1
3535
urllib3>=1.26.20,<2;python_version<"3.10"
36-
urllib3>=1.26.20,<2.4.0;python_version>="3.10"
36+
urllib3>=1.26.20,<2.5.0;python_version>="3.10"
3737
requests==2.32.3
3838
sniffio==1.3.1
3939
h11==0.14.0

seleniumbase/__version__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# seleniumbase package
2-
__version__ = "4.37.1"
2+
__version__ = "4.37.2"

seleniumbase/core/browser_launcher.py

+1
Original file line numberDiff line numberDiff line change
@@ -682,6 +682,7 @@ def uc_open_with_cdp_mode(driver, url=None):
682682
cdp.gui_click_element = CDPM.gui_click_element
683683
cdp.gui_drag_drop_points = CDPM.gui_drag_drop_points
684684
cdp.gui_drag_and_drop = CDPM.gui_drag_and_drop
685+
cdp.gui_click_and_hold = CDPM.gui_click_and_hold
685686
cdp.gui_hover_x_y = CDPM.gui_hover_x_y
686687
cdp.gui_hover_element = CDPM.gui_hover_element
687688
cdp.gui_hover_and_click = CDPM.gui_hover_and_click

seleniumbase/core/sb_cdp.py

+23-7
Original file line numberDiff line numberDiff line change
@@ -1227,15 +1227,23 @@ def get_element_rect(self, selector, timeout=None):
12271227
if not timeout:
12281228
timeout = settings.SMALL_TIMEOUT
12291229
selector = self.__convert_to_css_if_xpath(selector)
1230-
self.select(selector, timeout=timeout)
1230+
element = self.select(selector, timeout=timeout)
12311231
self.__add_light_pause()
1232-
coordinates = self.loop.run_until_complete(
1233-
self.page.js_dumps(
1234-
"""document.querySelector"""
1235-
"""('%s').getBoundingClientRect()"""
1236-
% js_utils.escape_quotes_if_needed(re.escape(selector))
1232+
coordinates = None
1233+
if ":contains(" in selector:
1234+
position = element.get_position()
1235+
x = position.x
1236+
y = position.y
1237+
width = position.width
1238+
height = position.height
1239+
coordinates = {"x": x, "y": y, "width": width, "height": height}
1240+
else:
1241+
coordinates = self.loop.run_until_complete(
1242+
self.page.js_dumps(
1243+
"""document.querySelector('%s').getBoundingClientRect()"""
1244+
% js_utils.escape_quotes_if_needed(re.escape(selector))
1245+
)
12371246
)
1238-
)
12391247
return coordinates
12401248

12411249
def get_element_size(self, selector, timeout=None):
@@ -1665,6 +1673,14 @@ def gui_drag_and_drop(self, drag_selector, drop_selector, timeframe=0.35):
16651673
self.__add_light_pause()
16661674
self.gui_drag_drop_points(x1, y1, x2, y2, timeframe=timeframe)
16671675

1676+
def gui_click_and_hold(self, selector, timeframe=0.35):
1677+
"""Use PyAutoGUI to click-and-hold a selector."""
1678+
self.__slow_mode_pause_if_set()
1679+
self.bring_active_window_to_front()
1680+
x, y = self.get_gui_element_center(selector)
1681+
self.__add_light_pause()
1682+
self.gui_drag_drop_points(x, y, x, y, timeframe=timeframe)
1683+
16681684
def __gui_hover_x_y(self, x, y, timeframe=0.25, uc_lock=False):
16691685
self.__install_pyautogui_if_missing()
16701686
import pyautogui

setup.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@
164164
"pynose>=1.5.4",
165165
'platformdirs>=4.3.6;python_version<"3.9"',
166166
'platformdirs>=4.3.7;python_version>="3.9"',
167-
'typing-extensions>=4.13.1',
167+
'typing-extensions>=4.13.2',
168168
"sbvirtualdisplay>=1.4.0",
169169
'MarkupSafe==2.1.5;python_version<"3.9"',
170170
'MarkupSafe>=3.0.2;python_version>="3.9"',
@@ -182,7 +182,7 @@
182182
'chardet==5.2.0',
183183
'charset-normalizer==3.4.1',
184184
'urllib3>=1.26.20,<2;python_version<"3.10"',
185-
'urllib3>=1.26.20,<2.4.0;python_version>="3.10"',
185+
'urllib3>=1.26.20,<2.5.0;python_version>="3.10"',
186186
'requests==2.32.3',
187187
'sniffio==1.3.1',
188188
'h11==0.14.0',

0 commit comments

Comments
 (0)