-
-
Notifications
You must be signed in to change notification settings - Fork 8.6k
Closed
Labels
A-needs-triagingA Selenium member will evaluate this soon!A Selenium member will evaluate this soon!
Description
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
Labels
A-needs-triagingA Selenium member will evaluate this soon!A Selenium member will evaluate this soon!