How do I upload multiple files with Protractor?

2019-02-19 04:53发布

问题:

I am using webdriver.WebElement.sendKeys and Path to upload a single file. The code looks like this:

var path = require('path'),
  uploadInput = element(by.css("input[type=file]")),
  fileToUpload = "../test_image/download.jpeg",
  absolutePath = path.resolve(__dirname, fileToUpload);

  uploadInput.sendKeys(absolutePath);

That works fine, for one file. I need to test multiple file uploads. How do I pass multiple files?

回答1:

Selenium still does not support multiple file uploads:

  • Support <input type=file multiple>

But, according to webdriver:upload multiple files, you should be able to solve it in Chrome by joining file paths with a new-line character:

uploadInput.sendKeys(absolutePath1 + "\n" + absolutePath2);

Also see:

  • File Upload - Uploading multiple files in FireFox