Skip to content

Commit

Permalink
[py] require enabling downloads
Browse files Browse the repository at this point in the history
  • Loading branch information
titusfortner committed Oct 30, 2023
1 parent fc45295 commit 4ea7207
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions py/selenium/webdriver/remote/webdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -1138,6 +1138,9 @@ def set_user_verified(self, verified: bool) -> None:
def get_downloadable_files(self) -> dict:
"""Retrieves the downloadable files as a map of file names and their
corresponding URLs."""
if "se:downloadsEnabled" not in self.capabilities:
raise WebDriverException("You must enable downloads in order to work with downloadable files.")

return self.execute(Command.GET_DOWNLOADABLE_FILES)["value"]["names"]

def download_file(self, file_name: str, target_directory: str) -> None:
Expand All @@ -1146,6 +1149,9 @@ def download_file(self, file_name: str, target_directory: str) -> None:
file_name: The name of the file to download.
target_directory: The path to the directory to save the downloaded file.
"""
if "se:downloadsEnabled" not in self.capabilities:
raise WebDriverException("You must enable downloads in order to work with downloadable files.")

if not os.path.exists(target_directory):
os.makedirs(target_directory)

Expand All @@ -1157,4 +1163,7 @@ def download_file(self, file_name: str, target_directory: str) -> None:

def delete_downloadable_files(self) -> None:
"""Deletes all downloadable files."""
if "se:downloadsEnabled" not in self.capabilities:
raise WebDriverException("You must enable downloads in order to work with downloadable files.")

self.execute(Command.DELETE_DOWNLOADABLE_FILES)

0 comments on commit 4ea7207

Please sign in to comment.