Skip to content

Commit

Permalink
Fix EOFError when calling the Remote WebDriver download_file method (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
millin authored Jun 4, 2024
1 parent cab1dd1 commit 635f7e2
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions py/selenium/webdriver/remote/webdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import copy
import os
import pkgutil
import tempfile
import types
import typing
import warnings
Expand Down Expand Up @@ -1147,12 +1148,13 @@ def download_file(self, file_name: str, target_directory: str) -> None:

contents = self.execute(Command.DOWNLOAD_FILE, {"name": file_name})["value"]["contents"]

target_file = os.path.join(target_directory, file_name)
with open(target_file, "wb") as file:
file.write(base64.b64decode(contents))
with tempfile.TemporaryDirectory() as tmp_dir:
zip_file = os.path.join(tmp_dir, file_name + ".zip")
with open(zip_file, "wb") as file:
file.write(base64.b64decode(contents))

with zipfile.ZipFile(target_file, "r") as zip_ref:
zip_ref.extractall(target_directory)
with zipfile.ZipFile(zip_file, "r") as zip_ref:
zip_ref.extractall(target_directory)

def delete_downloadable_files(self) -> None:
"""Deletes all downloadable files."""
Expand Down

0 comments on commit 635f7e2

Please sign in to comment.