@@ -416,18 +416,32 @@ def click(
416
416
)
417
417
):
418
418
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)
419
426
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
421
431
else:
422
432
# A smaller subset of self.wait_for_ready_state_complete()
423
- self.wait_for_angularjs(timeout=settings.MINI_TIMEOUT)
424
433
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)
427
435
except Exception:
428
- self.wait_for_ready_state_complete()
436
+ pass
437
+ try:
429
438
if self.driver.current_url != pre_action_url:
430
439
self.__ad_block_as_needed()
440
+ except Exception:
441
+ try:
442
+ self.wait_for_ready_state_complete()
443
+ except Exception:
444
+ pass
431
445
if self.browser == "safari":
432
446
time.sleep(0.02)
433
447
if self.demo_mode:
@@ -1218,8 +1232,18 @@ def click_link_text(self, link_text, timeout=None):
1218
1232
)
1219
1233
):
1220
1234
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)
1221
1242
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
1223
1247
if self.demo_mode:
1224
1248
if self.driver.current_url != pre_action_url:
1225
1249
self.__demo_mode_pause_if_active()
@@ -1355,8 +1379,18 @@ def click_partial_link_text(self, partial_link_text, timeout=None):
1355
1379
)
1356
1380
):
1357
1381
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)
1358
1389
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
1360
1394
if self.demo_mode:
1361
1395
if self.driver.current_url != pre_action_url:
1362
1396
self.__demo_mode_pause_if_active()
@@ -5104,7 +5138,17 @@ def js_click(
5104
5138
)
5105
5139
):
5106
5140
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
5108
5152
self.__demo_mode_pause_if_active()
5109
5153
5110
5154
def js_click_all(self, selector, by="css selector"):
0 commit comments