---
title: Uploading files with Selenium for testing | TestingBot Blog
description: |-
  Since a lot of websites have upload functionality, it's important to know that this can be tested via Selenium.

  Uploading a file during a test
source_url:
  html: https://testingbot.com/blog/2015/12/11/uploading-files-with-selenium-for-testing
  md: https://testingbot.com/blog/2015/12/11/uploading-files-with-selenium-for-testing.md
---

# Uploading with WebDriver

By [Jochen D.](https://testingbot.com/about/jochen-d)2015-12-11

 Share on Facebook 

 Share on Twitter 

 Post on Reddit 

 Share link 

Since a lot of websites have upload functionality, it's important to know that this can be tested via Selenium.

## Uploading a file during a test

With Selenium WebDriver it's possible to upload a file from your own computer. In your test, you indicate which file you would like to upload, after which WebDriver will send the file from your computer, base64-encoded, to the Selenium node.

When you want to upload a file during your test via the TestingBot.com selenium grid, you can use the `LocalFileDetector` feature in WebDriver to upload a file from the machine running your test to our test VMs. Since we guarantee a pristine virtual machine for every test, you can be sure that after every test your uploaded files are destroyed.

An example in Java:

```java
import junit.framework.*;
  
import org.openqa.selenium.*;
import org.openqa.selenium.remote.*; 

import java.io.InputStreamReader;
import java.io.OutputStreamWriter;

import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.FileInputStream;

import java.net.URL;  
  
public class UploadTest extends TestCase {
  
  public static void testUpload() {  
    String apiKey = "key";
    String apiSecret = "secret";

    DesiredCapabilities caps = new DesiredCapabilities();  
    caps.setCapability("browserName", "IE");  
    caps.setCapability("version", "9");  
    caps.setCapability("name", "Test File Upload"); 
    caps.setCapability("platform", "WINDOWS");  
  
    try {
      RemoteWebDriver driver = new RemoteWebDriver(new URL("http://" + apiKey + ":" + apiSecret + "@hub.testingbot.com/wd/hub"), caps);  
      driver.setFileDetector(new LocalFileDetector());
      
      driver.get("http://sl-test.herokuapp.com/guinea_pig/file_upload");
      WebElement upload = driver.findElement(By.id("myfile"));
      upload.sendKeys("~/mypicture.jpg");
      driver.findElement(By.id("submit")).click();
      driver.findElement(By.tagName("img"));
      Assert.assertEquals("mypicture.jpg (image/jpeg)", driver.findElement(By.tagName("p")).getText());  
      driver.quit();
    }
    catch (Exception ex) {
        System.out.println(ex.getMessage());
    }
  }  
}
```

## Uploading a file before starting a test

In some cases, you might want to make sure a file is already uploaded on our test VMs before your test starts. With TestingBot, you can specify the location (URL) of the file and the path where you want the file to be placed on our VMs. You can put these details in your desired capabilities (the options you send at the start of the test). TestingBot will then first download the file and place it in the location you want.

The way to do this is by specifying in your desired capabilities:

```java
{
browserName: "firefox",
version: 42,
platform: "VISTA",
upload: "http://mywebsite.com/myfile.ext",
uploadFilepath: "C:\\myfile.ext"
}
```

This will download the file from mywebsite.com/myfile.ext and place it in C:\myfile.ext During your test, you can use the C:\myfile.ext file to test your upload.

The same functionality is also available on our MAC and Linux VMs, where you can store them in the "/tmp" folder for example.

You can find more options for your tests on our [test options page](https://testingbot.com/support/web-automate/selenium/test-options).

[← Previous post TestingBot updates in October/November](https://testingbot.com/blog/2015/11/13/testingbot-updates-in-oktobernovember) [Next post → Cloud testing with Sikuli and Selenium WebDriver](https://testingbot.com/blog/2015/12/30/cloud-testing-with-sikuli-and-selenium-webdriver)

## Sidebar

### TestingBot Cloud Testing

Run automated, manual and visual tests on remote browsers and devices. Sign up for a free trial.

[Free Trial](https://testingbot.com/users/sign_up)

### Latest articles

[![Announcing AI Test Insights](https://testingbot.com/assets/blog/2026/ai-insights.jpg)](https://testingbot.com/blog/ai-test-insights)

#### Announcing AI Test Insights

Use AI Insights to quickly discover why an automated test...

[Read: Announcing AI Test Insights](https://testingbot.com/blog/ai-test-insights)

[![Selenium vs Playwright 2026](https://testingbot.com/assets/blog/2026/selenium-vs-playwright-2026.jpg)](https://testingbot.com/blog/selenium-vs-playwright)

#### Selenium vs Playwright 2026

Comparing Selenium vs Playwright - which is the best test...

[Read: Selenium vs Playwright 2026](https://testingbot.com/blog/selenium-vs-playwright)

[![Maestro Physical Device Testing](https://testingbot.com/assets/blog/2026/maestro-physical.jpg)](https://testingbot.com/blog/maestro-physical-device-testing)

#### Maestro Physical Device Testing

Maestro testing in parallel on physical Android and iOS d...

[Read: Maestro Physical Device Testing](https://testingbot.com/blog/maestro-physical-device-testing)

## Related Articles

[![Selenium vs Playwright 2026](https://testingbot.com/assets/blog/2026/selenium-vs-playwright-2026.jpg)](https://testingbot.com/blog/selenium-vs-playwright "Selenium vs Playwright 2026")

### [Selenium vs Playwright 2026](https://testingbot.com/blog/selenium-vs-playwright)

Comparing Selenium vs Playwright - which is the best test framework for your usecase?

[Read article →](https://testingbot.com/blog/selenium-vs-playwright)

[![Playwright Testing on TestingBot](https://testingbot.com/assets/blog/2023/playwright-testing.jpg)](https://testingbot.com/blog/playwright-testing-introduction "Playwright Testing on TestingBot")

### [Playwright Testing on TestingBot](https://testingbot.com/blog/playwright-testing-introduction)

Learn how Playwright can run your automated tests on a variety of browsers, local or remote browsers on TestingBot.

[Read article →](https://testingbot.com/blog/playwright-testing-introduction)

[![Selenium 20th birthday](https://testingbot.com/assets/blog/2024/selenium20.webp)](https://testingbot.com/blog/selenium-20-years "Selenium 20th birthday")

### [Selenium 20th birthday](https://testingbot.com/blog/selenium-20-years)

Celebrate Selenium's 20th birthday. An overview of the years.

[Read article →](https://testingbot.com/blog/selenium-20-years)

[![Electron Automated Testing](https://testingbot.com/assets/blog/2024/electron.webp)](https://testingbot.com/blog/electron-automated-testing "Electron Automated Testing")

### [Electron Automated Testing](https://testingbot.com/blog/electron-automated-testing)

TestingBot now supports running automated tests against Electron-based apps on remote Windows and macOS machines in the cloud.

[Read article →](https://testingbot.com/blog/electron-automated-testing)

## More by Jochen D.

[![Announcing AI Test Insights](https://testingbot.com/assets/blog/2026/ai-insights.jpg)](https://testingbot.com/blog/ai-test-insights "Announcing AI Test Insights")
### [Announcing AI Test Insights](https://testingbot.com/blog/ai-test-insights)

Use AI Insights to quickly discover why an automated test failed.

[![Maestro Physical Device Testing](https://testingbot.com/assets/blog/2026/maestro-physical.jpg)](https://testingbot.com/blog/maestro-physical-device-testing "Maestro Physical Device Testing")
### [Maestro Physical Device Testing](https://testingbot.com/blog/maestro-physical-device-testing)

Maestro testing in parallel on physical Android and iOS devices.

[![tvOS Physical Device Testing](https://testingbot.com/assets/blog/2025/appletv.jpg)](https://testingbot.com/blog/tvos-automated-testing "tvOS Physical Device Testing")
### [tvOS Physical Device Testing](https://testingbot.com/blog/tvos-automated-testing)

Run automated tvOS tests on physical AppleTV devices.

[See all posts by Jochen D. →](https://testingbot.com/about/jochen-d)

## Ready to start testing?
[Start a free trial](https://testingbot.com/users/sign_up)
