Skip to content

Commit 16de0c7

Browse files
committed
Make improvements around recording "Choose File" events
1 parent aecc892 commit 16de0c7

File tree

1 file changed

+37
-2
lines changed

1 file changed

+37
-2
lines changed

seleniumbase/fixtures/base_case.py

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3273,7 +3273,7 @@ def __process_recorded_actions(self):
32733273
and srt_actions[n-1][0] == "chfil"
32743274
):
32753275
srt_actions[n-1][0] = "_skip"
3276-
srt_actions[n][2] = srt_actions[n-1][1]
3276+
srt_actions[n][2] = srt_actions[n-1][1][1]
32773277
origins = []
32783278
for n in range(len(srt_actions)):
32793279
if (
@@ -3297,6 +3297,18 @@ def __process_recorded_actions(self):
32973297
srt_actions[n][0] = "h_clk"
32983298
srt_actions[n][1] = srt_actions[n-1][1][0]
32993299
srt_actions[n][2] = srt_actions[n-1][1][1]
3300+
for n in range(len(srt_actions)):
3301+
if srt_actions[n][0] == "chfil" and srt_actions[n][2] in origins:
3302+
srt_actions[n][0] = "cho_f"
3303+
srt_actions[n][2] = srt_actions[n][1][1]
3304+
srt_actions[n][1] = srt_actions[n][1][0]
3305+
for n in range(len(srt_actions)):
3306+
if (
3307+
srt_actions[n][0] == "sh_fc"
3308+
and n > 0
3309+
and srt_actions[n-1][0] == "sh_fc"
3310+
):
3311+
srt_actions[n-1][0] = "_skip"
33003312
ext_actions = []
33013313
ext_actions.append("js_cl")
33023314
ext_actions.append("as_el")
@@ -3312,6 +3324,7 @@ def __process_recorded_actions(self):
33123324
ext_actions.append("sw_dc")
33133325
ext_actions.append("s_c_f")
33143326
ext_actions.append("s_c_d")
3327+
ext_actions.append("sh_fc")
33153328
for n in range(len(srt_actions)):
33163329
if srt_actions[n][0] in ext_actions:
33173330
origin = srt_actions[n][2]
@@ -3521,6 +3534,9 @@ def __process_recorded_actions(self):
35213534
else:
35223535
sb_actions.append("self.%s('%s')" % (
35233536
method, action[1][0]))
3537+
elif action[0] == "sh_fc":
3538+
cb_method = "show_file_choosers"
3539+
sb_actions.append('self.%s()' % cb_method)
35243540
elif action[0] == "c_box":
35253541
cb_method = "check_if_unchecked"
35263542
if action[2] == "no":
@@ -4120,6 +4136,15 @@ def show_file_choosers(self):
41204136
self.execute_script(script)
41214137
except Exception:
41224138
pass
4139+
if self.recorder_mode:
4140+
url = self.get_current_url()
4141+
if url and len(url) > 0:
4142+
if ("http:") in url or ("https:") in url or ("file:") in url:
4143+
if self.get_session_storage_item("pause_recorder") == "no":
4144+
time_stamp = self.execute_script("return Date.now();")
4145+
origin = self.get_origin()
4146+
action = ["sh_fc", "", origin, time_stamp]
4147+
self.__extra_actions.append(action)
41234148

41244149
def get_domain_url(self, url):
41254150
self.__check_scope()
@@ -4440,6 +4465,15 @@ def choose_file(
44404465
self.__demo_mode_highlight_if_active(selector, by)
44414466
if not self.demo_mode and not self.slow_mode:
44424467
self.__scroll_to_element(element, selector, by)
4468+
else:
4469+
choose_file_selector = 'input[type="file"]'
4470+
if self.is_element_present(choose_file_selector):
4471+
if not self.is_element_visible(choose_file_selector):
4472+
self.show_file_choosers()
4473+
if self.is_element_visible(selector, by=by):
4474+
self.__demo_mode_highlight_if_active(selector, by)
4475+
if not self.demo_mode and not self.slow_mode:
4476+
self.__scroll_to_element(element, selector, by)
44434477
pre_action_url = self.driver.current_url
44444478
if self.recorder_mode:
44454479
url = self.get_current_url()
@@ -4448,7 +4482,8 @@ def choose_file(
44484482
if self.get_session_storage_item("pause_recorder") == "no":
44494483
time_stamp = self.execute_script("return Date.now();")
44504484
origin = self.get_origin()
4451-
action = ["chfil", file_path, origin, time_stamp]
4485+
sele_file_path = [selector, file_path]
4486+
action = ["chfil", sele_file_path, origin, time_stamp]
44524487
self.__extra_actions.append(action)
44534488
if type(abs_path) is int or type(abs_path) is float:
44544489
abs_path = str(abs_path)

0 commit comments

Comments
 (0)