@@ -166,6 +166,8 @@ def open(self, url):
166
166
"""Navigates the current browser window to the specified page."""
167
167
self.__check_scope()
168
168
self.__check_browser()
169
+ if self.__needs_minimum_wait():
170
+ time.sleep(0.01)
169
171
pre_action_url = None
170
172
try:
171
173
pre_action_url = self.driver.current_url
@@ -238,6 +240,8 @@ def open(self, url):
238
240
time.sleep(0.1) # Make sure load happens
239
241
if settings.WAIT_FOR_RSC_ON_PAGE_LOADS:
240
242
self.wait_for_ready_state_complete()
243
+ if self.__needs_minimum_wait():
244
+ time.sleep(0.03) # Force a minimum wait, even if skipping waits.
241
245
self.__demo_mode_pause_if_active()
242
246
243
247
def get(self, url):
@@ -461,12 +465,16 @@ def click(
461
465
self.wait_for_ready_state_complete()
462
466
except Exception:
463
467
pass
468
+ if self.__needs_minimum_wait():
469
+ time.sleep(0.02)
464
470
else:
465
471
# A smaller subset of self.wait_for_ready_state_complete()
466
472
try:
467
473
self.wait_for_angularjs(timeout=settings.MINI_TIMEOUT)
468
474
except Exception:
469
475
pass
476
+ if self.__needs_minimum_wait():
477
+ time.sleep(0.01)
470
478
try:
471
479
if self.driver.current_url != pre_action_url:
472
480
self.__ad_block_as_needed()
@@ -476,6 +484,8 @@ def click(
476
484
self.wait_for_ready_state_complete()
477
485
except Exception:
478
486
pass
487
+ if self.__needs_minimum_wait():
488
+ time.sleep(0.02)
479
489
if self.demo_mode:
480
490
if self.driver.current_url != pre_action_url:
481
491
self.__demo_mode_pause_if_active()
@@ -923,6 +933,8 @@ def get_origin(self):
923
933
924
934
def get_page_source(self):
925
935
self.wait_for_ready_state_complete()
936
+ if self.__needs_minimum_wait:
937
+ time.sleep(0.02)
926
938
return self.driver.page_source
927
939
928
940
def get_page_title(self):
@@ -2106,7 +2118,7 @@ def switch_to_frame_of_element(self, selector, by="css selector"):
2106
2118
element is in a single-nested iframe) and returns the iframe name.
2107
2119
If element is not in an iframe, returns None, and nothing happens.
2108
2120
May not work if multiple iframes are nested within each other."""
2109
- self.__check_scope ()
2121
+ self.wait_for_ready_state_complete ()
2110
2122
selector, by = self.__recalculate_selector(selector, by)
2111
2123
if self.is_element_present(selector, by=by):
2112
2124
return None
@@ -2890,7 +2902,11 @@ def switch_to_frame(self, frame, timeout=None):
2890
2902
action = ["sw_fr", frame, origin, time_stamp]
2891
2903
self.__extra_actions.append(action)
2892
2904
return
2905
+ self.wait_for_ready_state_complete()
2906
+ if self.__needs_minimum_wait():
2907
+ time.sleep(0.02)
2893
2908
page_actions.switch_to_frame(self.driver, frame, timeout)
2909
+ self.wait_for_ready_state_complete()
2894
2910
2895
2911
def switch_to_default_content(self):
2896
2912
"""Brings driver control outside the current iframe.
@@ -3701,6 +3717,16 @@ def delete_saved_cookies(self, name="cookies.txt"):
3701
3717
if cookies_file_path.endswith(".txt"):
3702
3718
os.remove(cookies_file_path)
3703
3719
3720
+ def __needs_minimum_wait(self):
3721
+ if (
3722
+ self.page_load_strategy == "none"
3723
+ and hasattr(settings, "SKIP_JS_WAITS")
3724
+ and settings.SKIP_JS_WAITS
3725
+ ):
3726
+ return True
3727
+ else:
3728
+ return False
3729
+
3704
3730
def __ad_block_as_needed(self):
3705
3731
"""This is an internal method for handling ad-blocking.
3706
3732
Use "pytest --ad-block" to enable this during tests.
@@ -3730,6 +3756,13 @@ def wait_for_ready_state_complete(self, timeout=None):
3730
3756
self.assert_no_js_errors()
3731
3757
self.__ad_block_as_needed()
3732
3758
self.__disable_beforeunload_as_needed()
3759
+ if (
3760
+ self.undetectable
3761
+ and self.page_load_strategy == "none"
3762
+ and hasattr(settings, "SKIP_JS_WAITS")
3763
+ and settings.SKIP_JS_WAITS
3764
+ ):
3765
+ time.sleep(0.03)
3733
3766
return True
3734
3767
3735
3768
def wait_for_angularjs(self, timeout=None, **kwargs):
@@ -5666,13 +5699,14 @@ def get_unique_links(self):
5666
5699
Page links include those obtained from:
5667
5700
"a"->"href", "img"->"src", "link"->"href", and "script"->"src".
5668
5701
"""
5669
- self.__check_scope()
5670
- if settings.SKIP_JS_WAITS and self.page_load_strategy == "none":
5671
- time.sleep(0.16)
5702
+ self.wait_for_ready_state_complete()
5672
5703
try:
5704
+ self.wait_for_element_present("body", timeout=1.5)
5673
5705
self.wait_for_element_visible("body", timeout=1.5)
5674
5706
except Exception:
5675
5707
pass
5708
+ if self.__needs_minimum_wait():
5709
+ time.sleep(0.25)
5676
5710
soup = self.get_beautiful_soup(self.get_page_source())
5677
5711
page_url = self.get_current_url()
5678
5712
links = page_utils._get_unique_links(page_url, soup)
@@ -11520,6 +11554,8 @@ def check_window(
11520
11554
self.check_window(name="wikipedia_page", level=3)
11521
11555
"""
11522
11556
self.wait_for_ready_state_complete()
11557
+ if self.__needs_minimum_wait():
11558
+ time.sleep(0.02) # Force a minimum wait, even if skipping waits.
11523
11559
try:
11524
11560
self.wait_for_element_visible(
11525
11561
"body", timeout=settings.MINI_TIMEOUT
@@ -12209,6 +12245,9 @@ def __click_with_offset(
12209
12245
):
12210
12246
from selenium.webdriver.common.action_chains import ActionChains
12211
12247
12248
+ self.wait_for_ready_state_complete()
12249
+ if self.__needs_minimum_wait():
12250
+ time.sleep(0.02) # Force a minimum wait, even if skipping waits.
12212
12251
if not timeout:
12213
12252
timeout = settings.SMALL_TIMEOUT
12214
12253
if self.timeout_multiplier and timeout == settings.SMALL_TIMEOUT:
0 commit comments