Skip to content

Commit 4a64acf

Browse files
committed
Improve method reliability and simplify exception-handling
1 parent e3a1ba5 commit 4a64acf

File tree

1 file changed

+19
-17
lines changed

1 file changed

+19
-17
lines changed

seleniumbase/fixtures/base_case.py

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -699,7 +699,9 @@ def click_link_text(self, link_text, timeout=None):
699699
try:
700700
self.__jquery_slow_scroll_to(link_text, by=By.LINK_TEXT)
701701
except Exception:
702-
pass
702+
element = self.wait_for_link_text_visible(
703+
link_text, timeout=timeout)
704+
self.__slow_scroll_to_element(element)
703705
o_bs = '' # original_box_shadow
704706
loops = settings.HIGHLIGHTS
705707
selector = self.convert_to_css_selector(
@@ -2120,7 +2122,7 @@ def switch_to_default_driver(self):
21202122

21212123
def save_screenshot(self, name, folder=None):
21222124
""" The screenshot will be in PNG format. """
2123-
self.__check_scope()
2125+
self.wait_for_ready_state_complete()
21242126
return page_actions.save_screenshot(self.driver, name, folder)
21252127

21262128
def save_page_source(self, name, folder=None):
@@ -2130,12 +2132,12 @@ def save_page_source(self, name, folder=None):
21302132
name - The file name to save the current page's HTML to.
21312133
folder - The folder to save the file to. (Default = current folder)
21322134
"""
2133-
self.__check_scope()
2135+
self.wait_for_ready_state_complete()
21342136
return page_actions.save_page_source(self.driver, name, folder)
21352137

21362138
def save_cookies(self, name="cookies.txt"):
21372139
""" Saves the page cookies to the "saved_cookies" folder. """
2138-
self.__check_scope()
2140+
self.wait_for_ready_state_complete()
21392141
cookies = self.driver.get_cookies()
21402142
json_cookies = json.dumps(cookies)
21412143
if name.endswith('/'):
@@ -2158,7 +2160,7 @@ def save_cookies(self, name="cookies.txt"):
21582160

21592161
def load_cookies(self, name="cookies.txt"):
21602162
""" Loads the page cookies from the "saved_cookies" folder. """
2161-
self.__check_scope()
2163+
self.wait_for_ready_state_complete()
21622164
if name.endswith('/'):
21632165
raise Exception("Invalid filename for Cookies!")
21642166
if '/' in name:
@@ -2183,13 +2185,13 @@ def load_cookies(self, name="cookies.txt"):
21832185
def delete_all_cookies(self):
21842186
""" Deletes all cookies in the web browser.
21852187
Does NOT delete the saved cookies file. """
2186-
self.__check_scope()
2188+
self.wait_for_ready_state_complete()
21872189
self.driver.delete_all_cookies()
21882190

21892191
def delete_saved_cookies(self, name="cookies.txt"):
21902192
""" Deletes the cookies file from the "saved_cookies" folder.
21912193
Does NOT delete the cookies from the web browser. """
2192-
self.__check_scope()
2194+
self.wait_for_ready_state_complete()
21932195
if name.endswith('/'):
21942196
raise Exception("Invalid filename for Cookies!")
21952197
if '/' in name:
@@ -2259,7 +2261,7 @@ def install_addon(self, xpi_file):
22592261
""" Installs a Firefox add-on instantly at run-time.
22602262
@Params
22612263
xpi_file - A file archive in .xpi format. """
2262-
self.__check_scope()
2264+
self.wait_for_ready_state_complete()
22632265
if self.browser != "firefox":
22642266
raise Exception(
22652267
"install_addon(xpi_file) is for Firefox ONLY!\n"
@@ -2271,20 +2273,20 @@ def install_addon(self, xpi_file):
22712273
def activate_design_mode(self):
22722274
# Activate Chrome's Design Mode, which lets you edit a site directly.
22732275
# See: https://twitter.com/sulco/status/1177559150563344384
2274-
self.__check_scope()
2276+
self.wait_for_ready_state_complete()
22752277
script = ("""document.designMode = 'on';""")
22762278
self.execute_script(script)
22772279

22782280
def deactivate_design_mode(self):
22792281
# Deactivate Chrome's Design Mode.
2280-
self.__check_scope()
2282+
self.wait_for_ready_state_complete()
22812283
script = ("""document.designMode = 'off';""")
22822284
self.execute_script(script)
22832285

22842286
def activate_jquery(self):
22852287
""" If "jQuery is not defined", use this method to activate it for use.
22862288
This happens because jQuery is not always defined on web sites. """
2287-
self.__check_scope()
2289+
self.wait_for_ready_state_complete()
22882290
js_utils.activate_jquery(self.driver)
22892291
self.wait_for_ready_state_complete()
22902292

@@ -2356,7 +2358,7 @@ def highlight(self, selector, by=By.CSS_SELECTOR,
23562358
self.__slow_scroll_to_element(element)
23572359
else:
23582360
self.__jquery_slow_scroll_to(selector, by)
2359-
except (StaleElementReferenceException, ENI_Exception, JS_Exc):
2361+
except Exception:
23602362
self.wait_for_ready_state_complete()
23612363
time.sleep(0.12)
23622364
element = self.wait_for_element_visible(
@@ -2405,11 +2407,11 @@ def highlight(self, selector, by=By.CSS_SELECTOR,
24052407
time.sleep(0.065)
24062408

24072409
def __highlight_with_js(self, selector, loops, o_bs):
2408-
self.__check_scope()
2410+
self.wait_for_ready_state_complete()
24092411
js_utils.highlight_with_js(self.driver, selector, loops, o_bs)
24102412

24112413
def __highlight_with_jquery(self, selector, loops, o_bs):
2412-
self.__check_scope()
2414+
self.wait_for_ready_state_complete()
24132415
js_utils.highlight_with_jquery(self.driver, selector, loops, o_bs)
24142416

24152417
def press_up_arrow(self, selector="html", times=1, by=By.CSS_SELECTOR):
@@ -2538,7 +2540,7 @@ def slow_scroll_to(self, selector, by=By.CSS_SELECTOR, timeout=None):
25382540
self.__jquery_slow_scroll_to(selector, by)
25392541
else:
25402542
self.__slow_scroll_to_element(element)
2541-
except (StaleElementReferenceException, ENI_Exception, JS_Exc):
2543+
except Exception:
25422544
self.wait_for_ready_state_complete()
25432545
time.sleep(0.12)
25442546
element = self.wait_for_element_visible(
@@ -6525,7 +6527,7 @@ def __highlight_with_assert_success(
65256527
self.__jquery_slow_scroll_to(selector, by)
65266528
else:
65276529
self.__slow_scroll_to_element(element)
6528-
except (StaleElementReferenceException, ENI_Exception):
6530+
except Exception:
65296531
self.wait_for_ready_state_complete()
65306532
time.sleep(0.12)
65316533
element = self.wait_for_element_visible(
@@ -6540,7 +6542,7 @@ def __highlight_with_assert_success(
65406542
o_bs = '' # original_box_shadow
65416543
try:
65426544
style = element.get_attribute('style')
6543-
except (StaleElementReferenceException, ENI_Exception):
6545+
except Exception:
65446546
self.wait_for_ready_state_complete()
65456547
time.sleep(0.12)
65466548
element = self.wait_for_element_visible(

0 commit comments

Comments
 (0)