0

How can I use a remote Selenium server instance, and test the uploading of files from the filesystem? If I use a remote Selenium server, how will that server be able to see what's on the local filesystem?

For example, I need to test uploading files to an API server, via a web interface. So Selenium will simulate the web interface, but since Selenium is running on a remote server, how can Selenium see the files on the filesystem?

1
  • Selenium automatically uploads the file when the method sendKeys is called with a valid file path on an <input> DOM element. But depending on the client, you may have to setup a file detector. Commented May 25, 2017 at 7:37

1 Answer 1

2

It depends how you are using selenium (framework & etc) But basic is when you are calling selenium to perform file upload you are making HTTP POST request to selenium remote server and sending local file as it's parameter.

Adds:

If you check Python framework here - https://github.com/SeleniumHQ/selenium/blob/fec87ea8c2a4704bd1e7bcddf9a98e400823ef4e/py/selenium/webdriver/remote/webelement.py

In "local" code you write path to file in send_keys function

if this function understand that it is file

local_file = self.parent.file_detector.is_local_file(*value) 

it will call def _upload in same file

it will zipped and encode it,

and pass to next function

return self._execute(Command.UPLOAD_FILE, {'file': content})['value'] 

In next file - you can find command which _upload executes

https://github.com/SeleniumHQ/selenium/blob/fec87ea8c2a4704bd1e7bcddf9a98e400823ef4e/py/selenium/webdriver/remote/remote_connection.py

def execute(self, command, params): Command.UPLOAD_FILE: ('POST', "/session/$sessionId/file") 
Sign up to request clarification or add additional context in comments.

3 Comments

right, but the "local" file is just the absolute file path to the file, when using file chooser dialog with web browser.
Yes, but you sending to selenium server not this absolute path, but file itself. Selenium getting file through post request, create temporary file from it and with driver upload temporary file to form of website you are testing.
hmm, ok, do you have a link showing how this is done with selenium?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.