@@ -3129,6 +3129,27 @@ def is_downloaded_file_present(self, file, browser=False):
3129
3129
return os .path .exists (self .get_path_of_downloaded_file (
3130
3130
file , browser = browser ))
3131
3131
3132
+ def delete_downloaded_file_if_present (self , file , browser = False ):
3133
+ """ Deletes the file from the [Downloads Folder] if the file exists.
3134
+ For browser click-initiated downloads, SeleniumBase will override
3135
+ the system [Downloads Folder] to be "./downloaded_files/",
3136
+ but that path can't be overridden when using Safari, IE,
3137
+ or Chromium Guest Mode, which keeps the default system path.
3138
+ self.download_file(file_url) will always use "./downloaded_files/".
3139
+ @Params
3140
+ file - The filename to be deleted from the [Downloads Folder].
3141
+ browser - If True, uses the path set by click-initiated downloads.
3142
+ If False, uses the self.download_file(file_url) path.
3143
+ Those paths are often the same. (browser-dependent)
3144
+ (Default: False).
3145
+ """
3146
+ if self .is_downloaded_file_present (file , browser = browser ):
3147
+ file_path = self .get_path_of_downloaded_file (file , browser = browser )
3148
+ try :
3149
+ os .remove (file_path )
3150
+ except Exception :
3151
+ pass
3152
+
3132
3153
def assert_downloaded_file (self , file , timeout = None , browser = False ):
3133
3154
""" Asserts that the file exists in SeleniumBase's [Downloads Folder].
3134
3155
For browser click-initiated downloads, SeleniumBase will override
0 commit comments