Skip to content

Red herring for Cygwin users in send_keys docstring #15272

@wemily

Description

@wemily

https://www.selenium.dev/selenium/docs/api/py/_modules/selenium/webdriver/remote/webelement.html#WebElement.send_keys

Generally it's better to wrap the file path in one of the methods in os.path to return the actual path to support cross OS testing.

That advice is misleading to Cygwin users getting InvalidArgumentException: File not found from send_keys with Geckodriver, which needs the Windows-style absolute path. On Cygwin, os.path returns Posix-style paths.

>>> os.path.exists("example.jpg")
True
>>> os.path.abspath("example.jpg")
'/home/user1/project2/example.jpg'

>>> file_input = self.driver.find_element(By.CSS_SELECTOR, "input[type='file']")
>>> file_input.send_keys(os.path.abspath("example.jpg"))
Traceback (most recent call last):
  File "/usr/lib/python3.7/site-packages/selenium/webdriver/remote/webelement.py", line 232, in send_keys
    Command.SEND_KEYS_TO_ELEMENT, {"text": "".join(keys_to_typing(value)), "value": keys_to_typing(value)}
  File "/usr/lib/python3.7/site-packages/selenium/webdriver/remote/webelement.py", line 395, in _execute
    return self._parent.execute(command, params)
  File "/usr/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 346, in execute
    self.error_handler.check_response(response)
  File "/usr/lib/python3.7/site-packages/selenium/webdriver/remote/errorhandler.py", line 245, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.InvalidArgumentException: Message: File not found: /home/user1/project2/example.jpg
Stacktrace:
RemoteError@chrome://remote/content/shared/RemoteError.sys.mjs:8:8
WebDriverError@chrome://remote/content/shared/webdriver/Errors.sys.mjs:187:5
InvalidArgumentError@chrome://remote/content/shared/webdriver/Errors.sys.mjs:378:5
interaction.uploadFiles@chrome://remote/content/marionette/interaction.sys.mjs:543:13

>>> path_that_works = ("c:/cygwin" + os.path.abspath("example.jpg")).replace("/", "\\")
>>> file_input.send_keys(path_that_works)
>>>

Also, a syntax error or something is preventing the "Examples" from being formatted as code here:
https://www.selenium.dev/selenium/docs/api/py/webdriver_remote/selenium.webdriver.remote.webelement.html#examples

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-needs-triagingA Selenium member will evaluate this soon!

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions