@@ -56,6 +56,9 @@ def __add_sync_methods(self, element):
5656 element , * args , ** kwargs
5757 )
5858 element .focus = lambda : self .__focus (element )
59+ element .gui_click = (
60+ lambda * args , ** kwargs : self .__gui_click (element , * args , ** kwargs )
61+ )
5962 element .highlight_overlay = lambda : self .__highlight_overlay (element )
6063 element .mouse_click = lambda : self .__mouse_click (element )
6164 element .mouse_drag = (
@@ -426,6 +429,39 @@ def __focus(self, element):
426429 self .loop .run_until_complete (element .focus_async ())
427430 )
428431
432+ def __gui_click (self , element , timeframe = None ):
433+ element .scroll_into_view ()
434+ self .__add_light_pause ()
435+ position = element .get_position ()
436+ x = position .x
437+ y = position .y
438+ e_width = position .width
439+ e_height = position .height
440+ # Relative to window
441+ element_rect = {"height" : e_height , "width" : e_width , "x" : x , "y" : y }
442+ window_rect = self .get_window_rect ()
443+ w_bottom_y = window_rect ["y" ] + window_rect ["height" ]
444+ viewport_height = window_rect ["innerHeight" ]
445+ x = window_rect ["x" ] + element_rect ["x" ]
446+ y = w_bottom_y - viewport_height + element_rect ["y" ]
447+ y_scroll_offset = window_rect ["pageYOffset" ]
448+ y = y - y_scroll_offset
449+ x = x + window_rect ["scrollX" ]
450+ y = y + window_rect ["scrollY" ]
451+ # Relative to screen
452+ element_rect = {"height" : e_height , "width" : e_width , "x" : x , "y" : y }
453+ e_width = element_rect ["width" ]
454+ e_height = element_rect ["height" ]
455+ e_x = element_rect ["x" ]
456+ e_y = element_rect ["y" ]
457+ x , y = ((e_x + e_width / 2.0 ) + 0.5 ), ((e_y + e_height / 2.0 ) + 0.5 )
458+ if not timeframe or not isinstance (timeframe , (int , float )):
459+ timeframe = 0.25
460+ if timeframe > 3 :
461+ timeframe = 3
462+ self .gui_click_x_y (x , y , timeframe = timeframe )
463+ return self .loop .run_until_complete (self .page .wait ())
464+
429465 def __highlight_overlay (self , element ):
430466 return (
431467 self .loop .run_until_complete (element .highlight_overlay_async ())
@@ -461,9 +497,7 @@ def __press_keys(self, element, text):
461497 element .send_keys ("\r \n " )
462498 time .sleep (0.044 )
463499 self .__slow_mode_pause_if_set ()
464- return (
465- self .loop .run_until_complete (self .page .wait ())
466- )
500+ return self .loop .run_until_complete (self .page .wait ())
467501
468502 def __query_selector (self , element , selector ):
469503 selector = self .__convert_to_css_if_xpath (selector )
0 commit comments