Skip to content

Commit 229c71a

Browse files
committed
Refactoring
1 parent 1f9aa4b commit 229c71a

File tree

1 file changed

+25
-13
lines changed

1 file changed

+25
-13
lines changed

seleniumbase/fixtures/base_case.py

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1130,15 +1130,11 @@ def get_title(self):
11301130
return self.get_page_title()
11311131

11321132
def get_user_agent(self):
1133-
self.__check_scope()
1134-
self.__check_browser()
1135-
user_agent = self.driver.execute_script("return navigator.userAgent;")
1133+
user_agent = self.execute_script("return navigator.userAgent;")
11361134
return user_agent
11371135

11381136
def get_locale_code(self):
1139-
self.__check_scope()
1140-
self.__check_browser()
1141-
locale_code = self.driver.execute_script(
1137+
locale_code = self.execute_script(
11421138
"return navigator.language || navigator.languages[0];"
11431139
)
11441140
return locale_code
@@ -1939,13 +1935,17 @@ def click_visible_elements(
19391935
self.wait_for_ready_state_complete()
19401936
if self.__needs_minimum_wait():
19411937
time.sleep(0.12)
1938+
if self.undetectable:
1939+
time.sleep(0.06)
19421940
element = self.wait_for_element_present(
19431941
selector, by=by, timeout=timeout
19441942
)
19451943
try:
19461944
# If the first element isn't visible, wait a little.
19471945
if not element.is_displayed():
19481946
time.sleep(0.16)
1947+
if self.undetectable:
1948+
time.sleep(0.06)
19491949
except Exception:
19501950
pass
19511951
elements = self.find_elements(selector, by=by)
@@ -2284,6 +2284,8 @@ def switch_to_frame_of_element(self, selector, by="css selector"):
22842284
self.wait_for_ready_state_complete()
22852285
if self.__needs_minimum_wait():
22862286
time.sleep(0.04)
2287+
if self.undetectable:
2288+
time.sleep(0.04)
22872289
selector, by = self.__recalculate_selector(selector, by)
22882290
if self.is_element_present(selector, by=by):
22892291
return None
@@ -2640,11 +2642,11 @@ def __element_click(self, element):
26402642
if len(href) > 0 and target == "_blank":
26412643
self.driver.tab_new(href)
26422644
self.switch_to_window(-1)
2643-
time.sleep(0.01)
26442645
elif len(href) > 0:
26452646
element.uc_click()
26462647
else:
26472648
element.click()
2649+
time.sleep(0.012)
26482650
except Exception:
26492651
element.click()
26502652

@@ -3069,16 +3071,22 @@ def switch_to_frame(self, frame, timeout=None):
30693071
timeout = self.__get_new_timeout(timeout)
30703072
if self.__needs_minimum_wait():
30713073
time.sleep(0.05)
3074+
if self.undetectable:
3075+
time.sleep(0.05)
30723076
if type(frame) is str and self.is_element_visible(frame):
30733077
try:
30743078
self.scroll_to(frame, timeout=1)
30753079
if self.__needs_minimum_wait():
30763080
time.sleep(0.04)
3081+
if self.undetectable:
3082+
time.sleep(0.04)
30773083
except Exception:
30783084
time.sleep(0.02)
30793085
else:
30803086
if self.__needs_minimum_wait():
30813087
time.sleep(0.05)
3088+
if self.undetectable:
3089+
time.sleep(0.05)
30823090
if self.undetectable:
30833091
self.__uc_frame_layer += 1
30843092
if self.recorder_mode and self._rec_overrides_switch:
@@ -3102,10 +3110,14 @@ def switch_to_frame(self, frame, timeout=None):
31023110
self.wait_for_ready_state_complete()
31033111
if self.__needs_minimum_wait():
31043112
time.sleep(0.035)
3113+
if self.undetectable:
3114+
time.sleep(0.035)
31053115
page_actions.switch_to_frame(self.driver, frame, timeout)
31063116
self.wait_for_ready_state_complete()
31073117
if self.__needs_minimum_wait():
31083118
time.sleep(0.015)
3119+
if self.undetectable:
3120+
time.sleep(0.015)
31093121

31103122
def switch_to_default_content(self):
31113123
"""Brings driver control outside the current iframe.
@@ -7530,7 +7542,7 @@ def start_recording_console_logs(self):
75307542
lost, and you'll have to call start_recording_console_logs() again.
75317543
# Link1: https://stackoverflow.com/a/19846113/7058266
75327544
# Link2: https://stackoverflow.com/a/74196986/7058266 """
7533-
self.driver.execute_script(
7545+
self.execute_script(
75347546
"""
75357547
console.stdlog = console.log.bind(console);
75367548
console.logs = [];
@@ -7545,19 +7557,19 @@ def console_log_string(self, string):
75457557
"""Log a string to the Web Browser's Console.
75467558
Example:
75477559
self.console_log_string("Hello World!") """
7548-
self.driver.execute_script("""console.log(`%s`);""" % string)
7560+
self.execute_script("""console.log(`%s`);""" % string)
75497561

75507562
def console_log_script(self, script):
75517563
"""Log output of JavaScript to the Web Browser's Console.
75527564
Example:
75537565
self.console_log_script('document.querySelector("h2").textContent') """
7554-
self.driver.execute_script("""console.log(%s);""" % script)
7566+
self.execute_script("""console.log(%s);""" % script)
75557567

75567568
def get_recorded_console_logs(self):
75577569
"""Get console logs recorded after "start_recording_console_logs()"."""
75587570
logs = []
75597571
try:
7560-
logs = self.driver.execute_script("return console.logs;")
7572+
logs = self.execute_script("return console.logs;")
75617573
except Exception:
75627574
pass
75637575
return logs
@@ -12125,7 +12137,7 @@ def __click_with_offset(
1212512137

1212612138
self.wait_for_ready_state_complete()
1212712139
if self.__needs_minimum_wait():
12128-
time.sleep(0.08) # Force a minimum wait, even if skipping waits.
12140+
time.sleep(0.14) # Force a minimum wait, even if skipping waits.
1212912141
if not timeout:
1213012142
timeout = settings.SMALL_TIMEOUT
1213112143
if self.timeout_multiplier and timeout == settings.SMALL_TIMEOUT:
@@ -12174,7 +12186,7 @@ def __click_with_offset(
1217412186
if element_location < 0:
1217512187
element_location = 0
1217612188
scroll_script = "window.scrollTo(0, %s);" % element_location
12177-
self.driver.execute_script(scroll_script)
12189+
self.execute_script(scroll_script)
1217812190
time.sleep(0.12)
1217912191
except Exception:
1218012192
time.sleep(0.05)

0 commit comments

Comments
 (0)