Skip to content

Commit f09b365

Browse files
authored
Choose File keyword should not fail if file_path is not file (robotframework#1403)
1 parent 57be0dc commit f09b365

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

atest/acceptance/keywords/forms_and_buttons.robot

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,24 @@ Click button created with <button> by tag content
5151
Verify Location Is "${FORM SUBMITTED}"
5252

5353
Choose File
54-
[Tags] Known Issue Internet Explorer Known Issue Safari
5554
[Setup] Navigate To File Upload Form And Create Temp File To Upload
5655
Choose File file_to_upload ${CURDIR}${/}temp.txt
5756
# Not sure do you get "C:\fakepath\" prefix with all browsers but at least
5857
# Chrome and Firefox use it regardless the OS.
5958
Textfield Value Should Be file_to_upload C:\\fakepath\\temp.txt
6059
[Teardown] Remove File ${CURDIR}${/}temp.txt
6160

61+
Choose File And File Does Not Exist
62+
[Setup] Go To Page "forms/file_upload_form.html"
63+
Run Keyword And Expect Error
64+
... InvalidArgumentException: Message:*
65+
... Choose File file_to_upload ${CURDIR}${/}NotHere.txt
66+
67+
Choose File And Folder
68+
[Setup] Go To Page "forms/file_upload_form.html"
69+
Choose File file_to_upload ${CURDIR}
70+
Textfield Value Should Be file_to_upload C:\\fakepath\\keywords
71+
6272
Click Image With Submit Type Images
6373
[Setup] Go To Page "forms/form_with_image_submit.html"
6474
Click Image robot.bmp

src/SeleniumLibrary/keywords/formelement.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -196,20 +196,21 @@ def choose_file(self, locator, file_path):
196196
"""Inputs the ``file_path`` into file input field ``locator``.
197197
198198
This keyword is most often used to input files into upload forms.
199-
The file specified with ``file_path`` must be available on machine
200-
where tests are executed. When using Selenium Grid, Seleniun will,
199+
Keyword does not check ``file_path`` is the file or folder
200+
available on machine where tests are executed. If the ``file_path``
201+
point sot a file and when using Selenium Grid, Selenium will,
201202
[https://seleniumhq.github.io/selenium/docs/api/py/webdriver_remote/selenium.webdriver.remote.command.html?highlight=upload#selenium.webdriver.remote.command.Command.UPLOAD_FILE|magically],
202203
transfer the file from the machine where test are executed
203204
to the Selenium Grid node where the browser is running.
204205
Then Selenium will send the file path, from to node file
205206
system, to the browser.
206207
208+
``file_path`` is not checked is new in SeleniumLibrary 4.0
209+
207210
Example:
208211
| `Choose File` | my_upload_field | ${CURDIR}/trades.csv |
209212
"""
210-
if not os.path.isfile(file_path):
211-
raise ValueError("File '%s' does not exist on the local file "
212-
"system." % file_path)
213+
self.info('Sending %s to browser.' % os.path.abspath(file_path))
213214
self.find_element(locator).send_keys(file_path)
214215

215216
@keyword

0 commit comments

Comments
 (0)