Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix EOFError when calling the Remote WebDriver download_file method #14031

Merged
merged 1 commit into from
Jun 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@

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))

Check warning on line 1154 in py/selenium/webdriver/remote/webdriver.py

View check run for this annotation

Codecov / codecov/patch

py/selenium/webdriver/remote/webdriver.py#L1154

Added line #L1154 was not covered by tests

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
Loading