@@ -795,15 +795,13 @@ def click_if_visible(self, selector, timeout=0):
795795 if self .is_element_visible (selector ):
796796 with suppress (Exception ):
797797 self .click (selector , timeout = 1 )
798+ elif timeout == 0 :
799+ return
798800 else :
799801 with suppress (Exception ):
800- element = self .find_element (selector , timeout = timeout )
801- self .sleep (0.1 )
802- element .scroll_into_view ()
803- self .sleep (0.1 )
804- element .click ()
805- self .__slow_mode_pause_if_set ()
806- self .loop .run_until_complete (self .page .wait ())
802+ self .find_element (selector , timeout = timeout )
803+ if self .is_element_visible (selector ):
804+ self .click (selector , timeout = 1 )
807805
808806 def click_visible_elements (self , selector , limit = 0 ):
809807 """Finds all matching page elements and clicks visible ones in order.
@@ -2068,14 +2066,35 @@ def __cdp_click_incapsula_hcaptcha(self):
20682066 time .sleep (0.05 )
20692067 x_offset = 30
20702068 y_offset = 36
2069+ was_clicked = False
20712070 gui_lock = FileLock (constants .MultiBrowser .PYAUTOGUILOCK )
20722071 with gui_lock : # Prevent issues with multiple processes
20732072 self .bring_active_window_to_front ()
2074- time .sleep (0.05 )
2073+ time .sleep (0.056 )
2074+ if "--debug" in sys .argv :
2075+ displayed_selector = "`%s`" % selector
2076+ if '"' not in selector :
2077+ displayed_selector = '"%s"' % selector
2078+ elif "'" not in selector :
2079+ displayed_selector = "'%s'" % selector
2080+ print (
2081+ " <DEBUG> click_with_offset(%s, %s, %s)"
2082+ % (displayed_selector , x_offset , y_offset )
2083+ )
20752084 with suppress (Exception ):
20762085 element .click_with_offset (x_offset , y_offset )
2077- time .sleep (0.2 )
2078- return True
2086+ was_clicked = True
2087+ time .sleep (0.056 )
2088+ if was_clicked :
2089+ # Wait a moment for the click to succeed
2090+ time .sleep (0.25 )
2091+ self .__slow_mode_pause_if_set ()
2092+ self .loop .run_until_complete (self .page .wait ())
2093+ if "--debug" in sys .argv :
2094+ print (" <DEBUG> hCaptcha was clicked!" )
2095+ return True
2096+ if "--debug" in sys .argv :
2097+ print (" <DEBUG> hCaptcha was NOT clicked!" )
20792098 return False
20802099
20812100 def solve_captcha (self ):
0 commit comments