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

[🐛 Bug]: Example on GitHub Error about Remote WebDriver #13957

Closed
15975518086 opened this issue May 17, 2024 · 1 comment · Fixed by #14031
Closed

[🐛 Bug]: Example on GitHub Error about Remote WebDriver #13957

15975518086 opened this issue May 17, 2024 · 1 comment · Fixed by #14031

Comments

@15975518086
Copy link

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 1

Operating 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

Copy link

@15975518086, thank you for creating this issue. We will troubleshoot it as soon as we can.


Info for maintainers

Triage this issue by using labels.

If information is missing, add a helpful comment and then I-issue-template label.

If the issue is a question, add the I-question label.

If the issue is valid but there is no time to troubleshoot it, consider adding the help wanted label.

If the issue requires changes or fixes from an external project (e.g., ChromeDriver, GeckoDriver, MSEdgeDriver, W3C), add the applicable G-* label, and it will provide the correct link and auto-close the issue.

After troubleshooting the issue, please add the R-awaiting answer label.

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants