Skip to content

Commit c44dea2

Browse files
committed
Refactor code for better compatibility with Appium
1 parent f3e8e45 commit c44dea2

File tree

1 file changed

+89
-20
lines changed

1 file changed

+89
-20
lines changed

seleniumbase/fixtures/base_case.py

Lines changed: 89 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,11 @@ def click(
406406
self.__demo_mode_highlight_if_active(original_selector, original_by)
407407
if scroll and not self.demo_mode and not self.slow_mode:
408408
self.__scroll_to_element(element, selector, by)
409-
pre_action_url = self.driver.current_url
409+
pre_action_url = None
410+
try:
411+
pre_action_url = self.driver.current_url
412+
except Exception:
413+
pass
410414
pre_window_count = len(self.driver.window_handles)
411415
try:
412416
if (
@@ -707,7 +711,11 @@ def double_click(self, selector, by="css selector", timeout=None):
707711
timeout=timeout,
708712
original_selector=original_selector,
709713
)
710-
pre_action_url = self.driver.current_url
714+
pre_action_url = None
715+
try:
716+
pre_action_url = self.driver.current_url
717+
except Exception:
718+
pass
711719
try:
712720
if self.browser == "safari":
713721
# Jump to the "except" block where the other script should work
@@ -788,7 +796,11 @@ def context_click(self, selector, by="css selector", timeout=None):
788796
timeout=timeout,
789797
original_selector=original_selector,
790798
)
791-
pre_action_url = self.driver.current_url
799+
pre_action_url = None
800+
try:
801+
pre_action_url = self.driver.current_url
802+
except Exception:
803+
pass
792804
try:
793805
if self.browser == "safari":
794806
# Jump to the "except" block where the other script should work
@@ -913,7 +925,12 @@ def update_text(
913925
except Exception:
914926
pass # Clearing the text field first might not be necessary
915927
self.__demo_mode_pause_if_active(tiny=True)
916-
pre_action_url = self.driver.current_url
928+
pre_action_url = None
929+
if self.demo_mode:
930+
try:
931+
pre_action_url = self.driver.current_url
932+
except Exception:
933+
pass
917934
text = self.__get_type_checked_text(text)
918935
try:
919936
if not text.endswith("\n"):
@@ -1011,7 +1028,12 @@ def add_text(self, selector, text, by="css selector", timeout=None):
10111028
self.__demo_mode_highlight_if_active(selector, by)
10121029
if not self.demo_mode and not self.slow_mode:
10131030
self.__scroll_to_element(element, selector, by)
1014-
pre_action_url = self.driver.current_url
1031+
pre_action_url = None
1032+
if self.demo_mode:
1033+
try:
1034+
pre_action_url = self.driver.current_url
1035+
except Exception:
1036+
pass
10151037
text = self.__get_type_checked_text(text)
10161038
try:
10171039
if not text.endswith("\n"):
@@ -1266,11 +1288,18 @@ def go_back(self):
12661288
self.__check_scope()
12671289
if hasattr(self, "recorder_mode") and self.recorder_mode:
12681290
self.save_recorded_actions()
1269-
pre_action_url = self.driver.current_url
1291+
pre_action_url = None
1292+
try:
1293+
pre_action_url = self.driver.current_url
1294+
except Exception:
1295+
pass
12701296
self.__last_page_load_url = None
12711297
self.driver.back()
1272-
if pre_action_url == self.driver.current_url:
1273-
self.driver.back() # Again because the page was redirected
1298+
try:
1299+
if pre_action_url == self.driver.current_url:
1300+
self.driver.back() # Again because the page was redirected
1301+
except Exception:
1302+
pass
12741303
if self.recorder_mode:
12751304
time_stamp = self.execute_script("return Date.now();")
12761305
origin = self.get_origin()
@@ -1529,8 +1558,6 @@ def click_link_text(self, link_text, timeout=None):
15291558
timeout = settings.SMALL_TIMEOUT
15301559
if self.timeout_multiplier and timeout == settings.SMALL_TIMEOUT:
15311560
timeout = self.__get_new_timeout(timeout)
1532-
pre_action_url = self.driver.current_url
1533-
pre_window_count = len(self.driver.window_handles)
15341561
link_text = self.__get_type_checked_text(link_text)
15351562
if self.browser == "safari":
15361563
if self.demo_mode:
@@ -1558,7 +1585,12 @@ def click_link_text(self, link_text, timeout=None):
15581585
return
15591586
if not self.is_link_text_present(link_text):
15601587
self.wait_for_link_text_present(link_text, timeout=timeout)
1561-
pre_action_url = self.driver.current_url
1588+
pre_action_url = None
1589+
try:
1590+
pre_action_url = self.driver.current_url
1591+
except Exception:
1592+
pass
1593+
pre_window_count = len(self.driver.window_handles)
15621594
try:
15631595
element = self.wait_for_link_text_visible(link_text, timeout=0.2)
15641596
self.__demo_mode_highlight_if_active(link_text, by="link text")
@@ -1654,7 +1686,11 @@ def click_partial_link_text(self, partial_link_text, timeout=None):
16541686
self.wait_for_partial_link_text_present(
16551687
partial_link_text, timeout=timeout
16561688
)
1657-
pre_action_url = self.driver.current_url
1689+
pre_action_url = None
1690+
try:
1691+
pre_action_url = self.driver.current_url
1692+
except Exception:
1693+
pass
16581694
pre_window_count = len(self.driver.window_handles)
16591695
try:
16601696
element = self.wait_for_partial_link_text(
@@ -2125,7 +2161,11 @@ def click_visible_elements(
21252161
except Exception:
21262162
pass
21272163
elements = self.find_elements(selector, by=by)
2128-
pre_action_url = self.driver.current_url
2164+
pre_action_url = None
2165+
try:
2166+
pre_action_url = self.driver.current_url
2167+
except Exception:
2168+
pass
21292169
pre_window_count = len(self.driver.window_handles)
21302170
click_count = 0
21312171
for element in elements:
@@ -2207,7 +2247,11 @@ def click_nth_visible_element(
22072247
if number < 0:
22082248
number = 0
22092249
element = elements[number]
2210-
pre_action_url = self.driver.current_url
2250+
pre_action_url = None
2251+
try:
2252+
pre_action_url = self.driver.current_url
2253+
except Exception:
2254+
pass
22112255
pre_window_count = len(self.driver.window_handles)
22122256
try:
22132257
self.__scroll_to_element(element)
@@ -2261,7 +2305,11 @@ def click_if_visible(self, selector, by="css selector", timeout=0):
22612305

22622306
def click_active_element(self):
22632307
self.wait_for_ready_state_complete()
2264-
pre_action_url = self.driver.current_url
2308+
pre_action_url = None
2309+
try:
2310+
pre_action_url = self.driver.current_url
2311+
except Exception:
2312+
pass
22652313
pre_window_count = len(self.driver.window_handles)
22662314
if self.recorder_mode:
22672315
selector = js_utils.get_active_element_css(self.driver)
@@ -2593,7 +2641,11 @@ def hover_and_click(
25932641
)
25942642
self.__demo_mode_highlight_if_active(original_selector, original_by)
25952643
self.scroll_to(hover_selector, by=hover_by)
2596-
pre_action_url = self.driver.current_url
2644+
pre_action_url = None
2645+
try:
2646+
pre_action_url = self.driver.current_url
2647+
except Exception:
2648+
pass
25972649
pre_window_count = len(self.driver.window_handles)
25982650
if self.recorder_mode and self.__current_url_is_recordable():
25992651
if self.get_session_storage_item("pause_recorder") == "no":
@@ -2719,7 +2771,11 @@ def hover_and_double_click(
27192771
)
27202772
self.__demo_mode_highlight_if_active(original_selector, original_by)
27212773
self.scroll_to(hover_selector, by=hover_by)
2722-
pre_action_url = self.driver.current_url
2774+
pre_action_url = None
2775+
try:
2776+
pre_action_url = self.driver.current_url
2777+
except Exception:
2778+
pass
27232779
pre_window_count = len(self.driver.window_handles)
27242780
outdated_driver = False
27252781
element = None
@@ -2906,7 +2962,11 @@ def __select_option(
29062962
self.__demo_mode_highlight_if_active(
29072963
dropdown_selector, dropdown_by
29082964
)
2909-
pre_action_url = self.driver.current_url
2965+
pre_action_url = None
2966+
try:
2967+
pre_action_url = self.driver.current_url
2968+
except Exception:
2969+
pass
29102970
pre_window_count = len(self.driver.window_handles)
29112971
try:
29122972
if option_by == "index":
@@ -5802,7 +5862,11 @@ def js_click(
58025862
css_selector = self.__escape_quotes_if_needed(css_selector)
58035863
time_stamp = 0
58045864
action = ["", "", "", time_stamp]
5805-
pre_action_url = self.driver.current_url
5865+
pre_action_url = None
5866+
try:
5867+
pre_action_url = self.driver.current_url
5868+
except Exception:
5869+
pass
58065870
pre_window_count = len(self.driver.window_handles)
58075871
if self.recorder_mode and not self.__dont_record_js_click:
58085872
time_stamp = self.execute_script("return Date.now();")
@@ -6684,7 +6748,12 @@ def choose_file(
66846748
self.__demo_mode_highlight_if_active(selector, by)
66856749
if not self.demo_mode and not self.slow_mode:
66866750
self.__scroll_to_element(element, selector, by)
6687-
pre_action_url = self.driver.current_url
6751+
pre_action_url = None
6752+
if self.demo_mode:
6753+
try:
6754+
pre_action_url = self.driver.current_url
6755+
except Exception:
6756+
pass
66886757
if self.recorder_mode and self.__current_url_is_recordable():
66896758
if self.get_session_storage_item("pause_recorder") == "no":
66906759
time_stamp = self.execute_script("return Date.now();")

0 commit comments

Comments
 (0)