@@ -1227,15 +1227,23 @@ def get_element_rect(self, selector, timeout=None):
1227
1227
if not timeout :
1228
1228
timeout = settings .SMALL_TIMEOUT
1229
1229
selector = self .__convert_to_css_if_xpath (selector )
1230
- self .select (selector , timeout = timeout )
1230
+ element = self .select (selector , timeout = timeout )
1231
1231
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
+ )
1237
1246
)
1238
- )
1239
1247
return coordinates
1240
1248
1241
1249
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):
1665
1673
self .__add_light_pause ()
1666
1674
self .gui_drag_drop_points (x1 , y1 , x2 , y2 , timeframe = timeframe )
1667
1675
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
+
1668
1684
def __gui_hover_x_y (self , x , y , timeframe = 0.25 , uc_lock = False ):
1669
1685
self .__install_pyautogui_if_missing ()
1670
1686
import pyautogui
0 commit comments