Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Upload a file

Ondřej Machulda edited this page Nov 25, 2020 · 8 revisions

In order to make file uploads working properly on remote browsers, you must use LocalFileDetector(). This will take care of transferring the file on the machine whre the actual browser is being run, which may not be your computer (it could be on remote CI server, in Docker etc.)

Consider the following <input> html element:

<form ...>

<!-- Upload input element -->
<input type="file" id="file_input"></input>

</form>

Your upload code will look like this:

  // getting the input element
  $fileInput = $driver->findElement(WebDriverBy::id('file_input'));

  // set the file detector on the file_input element
  $fileInput->setFileDetector(new LocalFileDetector());

  // upload the file and immediatelly submit the form
  $fileInput->sendKeys($filePath)
      ->submit();

  // you can also just fill the file input and submit the form later
  $fileInput->sendKeys($filePath);
  // ... do some other stuff in the form, then submit the whole form:
  $form->submit(); // if form is WebDriverElement representing <form>

Clone this wiki locally

Morty Proxy This is a proxified and sanitized view of the page, visit original site.