@@ -2964,7 +2964,33 @@ def choose_file(self, selector, file_path, by=By.CSS_SELECTOR,
2964
2964
timeout = self .__get_new_timeout (timeout )
2965
2965
selector , by = self .__recalculate_selector (selector , by )
2966
2966
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 ()
2968
2994
2969
2995
def save_element_as_image_file (
2970
2996
self , selector , file_name , folder = None , overlay_text = "" ):
0 commit comments