Skip to content

[🐛 Bug]: send_keys hits OSError with over 255 characters of text #12474

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

Closed
ALHopkins opened this issue Aug 2, 2023 · 7 comments
Closed

[🐛 Bug]: send_keys hits OSError with over 255 characters of text #12474

ALHopkins opened this issue Aug 2, 2023 · 7 comments
Labels
C-py Python Bindings I-defect Something is not working as intended

Comments

@ALHopkins
Copy link

ALHopkins commented Aug 2, 2023

What happened?

In python, using send_keys to submit over 255 characters of text to the page will result in OSError: [Errno 36] File name too long. Previous versions of Selenium (EG 4.8.0) would ignore this error because LocalFileDetector.is_local_file had an exception catch, which was removed by this MR #12253

How can we reproduce the issue?

from selenium import webdriver
from selenium.webdriver.common.by import By

options = webdriver.ChromeOptions()
driver = webdriver.Remote(
        command_executor='http://127.0.0.1:4444/wd/hub',
        options=options)

driver.get("http://www.google.com")
driver.find_element(By.XPATH, "//textarea[@class='gLFyf']").send_keys(
    "123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 "
    "123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 "
    "123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 "
    "123456789 123456")


### Relevant log output

```shell
/src/project/venv310/bin/python /src/project/scratch/bug_demo.py 
Traceback (most recent call last):
  File "/src/project/scratch/bug_demo.py", line 10, in <module>
    driver.find_element(By.XPATH, "//textarea[@class='gLFyf']").send_keys(
  File "/src/project/venv310/lib/python3.10/site-packages/selenium/webdriver/remote/webelement.py", line 219, in send_keys
    local_files = list(
  File "/src/project/venv310/lib/python3.10/site-packages/selenium/webdriver/remote/webelement.py", line 221, in <lambda>
    lambda keys_to_send: self.parent.file_detector.is_local_file(str(keys_to_send)),
  File "/src/project/venv310/lib/python3.10/site-packages/selenium/webdriver/remote/file_detector.py", line 49, in is_local_file
    return file_path if path.is_file() else None
  File "/usr/lib/python3.10/pathlib.py", line 1322, in is_file
    return S_ISREG(self.stat().st_mode)
  File "/usr/lib/python3.10/pathlib.py", line 1097, in stat
    return self._accessor.stat(self, follow_symlinks=follow_symlinks)
OSError: [Errno 36] File name too long: '123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456'

Process finished with exit code 1

Operating System

Ubuntu 22.04

Selenium version

Python 3.10.12, Selenium 4.11.2

What are the browser(s) and version(s) where you see this issue?

Chrome: 115.0.5790.110

What are the browser driver(s) and version(s) where you see this issue?

ChromeDriver: 115.0.5790.102

Are you using Selenium Grid?

selenium/standalone-chrome:4.11.0-20230801

@ALHopkins ALHopkins added I-defect Something is not working as intended A-needs-triaging A Selenium member will evaluate this soon! labels Aug 2, 2023
@github-actions
Copy link

github-actions bot commented Aug 2, 2023

@ALHopkins, 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!

@diemol
Copy link
Member

diemol commented Aug 2, 2023

@ALHopkins does this happen in Firefox as well?

@diemol diemol added J-awaiting answer Question asked of user; a reply moves it to triage again and removed A-needs-triaging A Selenium member will evaluate this soon! labels Aug 2, 2023
@ALHopkins
Copy link
Author

Yes, just ran it against selenium/standalone-firefox:4.11.0-20230801 changing options = webdriver.ChromeOptions() to options = webdriver.FirefoxOptions() and got the same error.

@titusfortner
Copy link
Member

that's weird that Python lets that error, but I'm sure there are reasons.

Yes, we need to put the try/catch back. @sandeepsuryaprasad I think we can keep the Path(file_path) but we need to put the try/except back.

@titusfortner titusfortner added C-py Python Bindings and removed J-awaiting answer Question asked of user; a reply moves it to triage again labels Aug 2, 2023
@symonk
Copy link
Member

symonk commented Aug 2, 2023

Thanks for reporting, pretty clear the unit/integration tests in the repo are lacking! The core surrounding that logic is quite weird, reliant on a None value being returned; we need to handle the exceptions on is_file() here.

@symonk
Copy link
Member

symonk commented Aug 2, 2023

Apologies for the commit spam, was fixing on mobile during lunch break! Will ship in the next release, thanks for a great clear, reproducible report.

Copy link

github-actions bot commented Dec 9, 2023

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked and limited conversation to collaborators Dec 9, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
C-py Python Bindings I-defect Something is not working as intended
Projects
None yet
Development

No branches or pull requests

4 participants