Skip to content

Commit e710ef2

Browse files
committed
Allow the choose_file() method to work on hidden "input" fields
1 parent 5597d71 commit e710ef2

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

seleniumbase/fixtures/base_case.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2964,7 +2964,33 @@ def choose_file(self, selector, file_path, by=By.CSS_SELECTOR,
29642964
timeout = self.__get_new_timeout(timeout)
29652965
selector, by = self.__recalculate_selector(selector, by)
29662966
abs_path = os.path.abspath(file_path)
2967-
self.add_text(selector, abs_path, by=by, timeout=timeout)
2967+
element = self.wait_for_element_present(
2968+
selector, by=by, timeout=timeout)
2969+
if self.is_element_visible(selector, by=by):
2970+
self.__demo_mode_highlight_if_active(selector, by)
2971+
if not self.demo_mode and not self.slow_mode:
2972+
self.__scroll_to_element(element, selector, by)
2973+
pre_action_url = self.driver.current_url
2974+
if type(abs_path) is int or type(abs_path) is float:
2975+
abs_path = str(abs_path)
2976+
try:
2977+
element.send_keys(abs_path)
2978+
except (StaleElementReferenceException, ENI_Exception):
2979+
self.wait_for_ready_state_complete()
2980+
time.sleep(0.16)
2981+
element = self.wait_for_element_present(
2982+
selector, by=by, timeout=timeout)
2983+
element.send_keys(abs_path)
2984+
except Exception:
2985+
exc_message = self.__get_improved_exception_message()
2986+
raise Exception(exc_message)
2987+
if self.demo_mode:
2988+
if self.driver.current_url != pre_action_url:
2989+
self.__demo_mode_pause_if_active()
2990+
else:
2991+
self.__demo_mode_pause_if_active(tiny=True)
2992+
elif self.slow_mode:
2993+
self.__slow_mode_pause_if_active()
29682994

29692995
def save_element_as_image_file(
29702996
self, selector, file_name, folder=None, overlay_text=""):

0 commit comments

Comments
 (0)