-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
Description
What happened?
Use the Example on GitHub , found it fail to download jpg file
Examplelink:
https://github.com/SeleniumHQ/seleniumhq.github.io/blob/trunk/examples/python/tests/drivers/test_remote_webdriver.py#L10-L11
codes :
import os
import time
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.remote.file_detector import LocalFileDetector
from selenium.webdriver.support.wait import WebDriverWait
options = webdriver.ChromeOptions()
options.enable_downloads = True
driver = webdriver.Remote(command_executor='http://192.168.3.35:4444/wd/hub', options=options)
file_names = ["file_1.txt", "file_2.jpg"]
driver.get('https://www.selenium.dev/selenium/web/downloads/download.html')
driver.find_element(By.ID, "file-1").click()
driver.find_element(By.ID, "file-2").click()
WebDriverWait(driver, 3).until(lambda d: "file_2.jpg" in d.get_downloadable_files())
files = driver.get_downloadable_files()
assert sorted(files) == sorted(file_names)
downloadable_file = file_names[1]
target_directory = r'D:\dtmp'
driver.download_file(downloadable_file, target_directory)
error:
D:\Python\Python311\python.exe D:/OfflineaCare/ndb/program/test/test_oooooooo1.py
Traceback (most recent call last):
File "D:\OfflineaCare\ndb\program\test\test_oooooooo1.py", line 26, in
driver.download_file(downloadable_file, target_directory)
File "D:\Python\Python311\Lib\site-packages\selenium\webdriver\remote\webdriver.py", line 1155, in download_file
zip_ref.extractall(target_directory)
File "D:\Python\Python311\Lib\zipfile.py", line 1679, in extractall
self._extract_member(zipinfo, path, pwd)
File "D:\Python\Python311\Lib\zipfile.py", line 1734, in _extract_member
shutil.copyfileobj(source, target)
File "D:\Python\Python311\Lib\shutil.py", line 197, in copyfileobj
buf = fsrc_read(length)
^^^^^^^^^^^^^^^^^
File "D:\Python\Python311\Lib\zipfile.py", line 953, in read
data = self._read1(n)
^^^^^^^^^^^^^^
File "D:\Python\Python311\Lib\zipfile.py", line 1021, in _read1
data += self._read2(n - len(data))
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Python\Python311\Lib\zipfile.py", line 1056, in _read2
raise EOFError
EOFError
Process finished with exit code 1
How can we reproduce the issue?
https://github.com/SeleniumHQ/seleniumhq.github.io/blob/trunk/examples/python/tests/drivers/test_remote_webdriver.py#L10-L11
example about :'test_downloads'
just download the 'file_2.jpg' ,in this sameple
change downloadable_file = file_names[0] to be downloadable_file = file_names[1]Relevant log output
D:\Python\Python311\python.exe D:/OfflineaCare/ndb/program/test/test_oooooooo1.py
['file_2.jpg']
Traceback (most recent call last):
File "D:\OfflineaCare\ndb\program\test\test_oooooooo1.py", line 29, in <module>
driver.download_file(downloadable_file, target_directory)
File "D:\Python\Python311\Lib\site-packages\selenium\webdriver\remote\webdriver.py", line 1155, in download_file
zip_ref.extractall(target_directory)
File "D:\Python\Python311\Lib\zipfile.py", line 1679, in extractall
self._extract_member(zipinfo, path, pwd)
File "D:\Python\Python311\Lib\zipfile.py", line 1734, in _extract_member
shutil.copyfileobj(source, target)
File "D:\Python\Python311\Lib\shutil.py", line 197, in copyfileobj
buf = fsrc_read(length)
^^^^^^^^^^^^^^^^^
File "D:\Python\Python311\Lib\zipfile.py", line 953, in read
data = self._read1(n)
^^^^^^^^^^^^^^
File "D:\Python\Python311\Lib\zipfile.py", line 1021, in _read1
data += self._read2(n - len(data))
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Python\Python311\Lib\zipfile.py", line 1056, in _read2
raise EOFError
EOFError
Process finished with exit code 1Operating System
WINDOWS10
Selenium version
selenium 4.20.0 python 3.11.3
What are the browser(s) and version(s) where you see this issue?
Chrome 124
What are the browser driver(s) and version(s) where you see this issue?
124.0.6367.61
Are you using Selenium Grid?
selenium-server-4.20.0.jar