Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion atest/acceptance/keywords/forms_and_buttons.robot
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,24 @@ Click button created with <button> by tag content
Verify Location Is "${FORM SUBMITTED}"

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

Choose File And File Does Not Exist
[Setup] Go To Page "forms/file_upload_form.html"
Run Keyword And Expect Error
... InvalidArgumentException: Message:*
... Choose File file_to_upload ${CURDIR}${/}NotHere.txt

Choose File And Folder
[Setup] Go To Page "forms/file_upload_form.html"
Choose File file_to_upload ${CURDIR}
Textfield Value Should Be file_to_upload C:\\fakepath\\keywords

Click Image With Submit Type Images
[Setup] Go To Page "forms/form_with_image_submit.html"
Click Image robot.bmp
Expand Down
11 changes: 6 additions & 5 deletions src/SeleniumLibrary/keywords/formelement.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,20 +196,21 @@ def choose_file(self, locator, file_path):
"""Inputs the ``file_path`` into file input field ``locator``.

This keyword is most often used to input files into upload forms.
The file specified with ``file_path`` must be available on machine
where tests are executed. When using Selenium Grid, Seleniun will,
Keyword does not check ``file_path`` is the file or folder
available on machine where tests are executed. If the ``file_path``
point sot a file and when using Selenium Grid, Selenium will,
[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],
transfer the file from the machine where test are executed
to the Selenium Grid node where the browser is running.
Then Selenium will send the file path, from to node file
system, to the browser.

``file_path`` is not checked is new in SeleniumLibrary 4.0

Example:
| `Choose File` | my_upload_field | ${CURDIR}/trades.csv |
"""
if not os.path.isfile(file_path):
raise ValueError("File '%s' does not exist on the local file "
"system." % file_path)
self.info('Sending %s to browser.' % os.path.abspath(file_path))
self.find_element(locator).send_keys(file_path)

@keyword
Expand Down