@@ -416,18 +416,32 @@ def click(
416416 )
417417 ):
418418 self.__switch_to_newest_window_if_not_blank()
419+ elif (
420+ latest_window_count == pre_window_count - 1
421+ and latest_window_count > 0
422+ ):
423+ # If a click closes the active window,
424+ # switch to the last one if it exists.
425+ self.switch_to_window(-1)
419426 if settings.WAIT_FOR_RSC_ON_CLICKS:
420- self.wait_for_ready_state_complete()
427+ try:
428+ self.wait_for_ready_state_complete()
429+ except Exception:
430+ pass
421431 else:
422432 # A smaller subset of self.wait_for_ready_state_complete()
423- self.wait_for_angularjs(timeout=settings.MINI_TIMEOUT)
424433 try:
425- if self.driver.current_url != pre_action_url:
426- self.__ad_block_as_needed()
434+ self.wait_for_angularjs(timeout=settings.MINI_TIMEOUT)
427435 except Exception:
428- self.wait_for_ready_state_complete()
436+ pass
437+ try:
429438 if self.driver.current_url != pre_action_url:
430439 self.__ad_block_as_needed()
440+ except Exception:
441+ try:
442+ self.wait_for_ready_state_complete()
443+ except Exception:
444+ pass
431445 if self.browser == "safari":
432446 time.sleep(0.02)
433447 if self.demo_mode:
@@ -1218,8 +1232,18 @@ def click_link_text(self, link_text, timeout=None):
12181232 )
12191233 ):
12201234 self.__switch_to_newest_window_if_not_blank()
1235+ elif (
1236+ latest_window_count == pre_window_count - 1
1237+ and latest_window_count > 0
1238+ ):
1239+ # If a click closes the active window,
1240+ # switch to the last one if it exists.
1241+ self.switch_to_window(-1)
12211242 if settings.WAIT_FOR_RSC_ON_PAGE_LOADS:
1222- self.wait_for_ready_state_complete()
1243+ try:
1244+ self.wait_for_ready_state_complete()
1245+ except Exception:
1246+ pass
12231247 if self.demo_mode:
12241248 if self.driver.current_url != pre_action_url:
12251249 self.__demo_mode_pause_if_active()
@@ -1355,8 +1379,18 @@ def click_partial_link_text(self, partial_link_text, timeout=None):
13551379 )
13561380 ):
13571381 self.__switch_to_newest_window_if_not_blank()
1382+ elif (
1383+ latest_window_count == pre_window_count - 1
1384+ and latest_window_count > 0
1385+ ):
1386+ # If a click closes the active window,
1387+ # switch to the last one if it exists.
1388+ self.switch_to_window(-1)
13581389 if settings.WAIT_FOR_RSC_ON_PAGE_LOADS:
1359- self.wait_for_ready_state_complete()
1390+ try:
1391+ self.wait_for_ready_state_complete()
1392+ except Exception:
1393+ pass
13601394 if self.demo_mode:
13611395 if self.driver.current_url != pre_action_url:
13621396 self.__demo_mode_pause_if_active()
@@ -5104,7 +5138,17 @@ def js_click(
51045138 )
51055139 ):
51065140 self.__switch_to_newest_window_if_not_blank()
5107- self.wait_for_ready_state_complete()
5141+ elif (
5142+ latest_window_count == pre_window_count - 1
5143+ and latest_window_count > 0
5144+ ):
5145+ # If a click closes the active window,
5146+ # switch to the last one if it exists.
5147+ self.switch_to_window(-1)
5148+ try:
5149+ self.wait_for_ready_state_complete()
5150+ except Exception:
5151+ pass
51085152 self.__demo_mode_pause_if_active()
51095153
51105154 def js_click_all(self, selector, by="css selector"):
0 commit comments