I want to test the image upload functionality using Protractor but my written script didn't work.

This is the image dialogue box.

When we click on the dialogue box image it opens the window to select the desired image. After the selection of the image, the box acts like below:


I want to write a script through which I can upload an image and then click on the "Save" button.

This is the css of a dialogue box.

This is the Error message that encounteredenter image description here

Given below is the script that I tried but doesn't work:

 var path = require('path');
 var fileToUpload = '../new image.jpeg';
 var absolutePath = path.resolve('__dirname', fileToUpload);
 var fileElem=element(by.css('label[for="cropper-file-input"]'));
 browser.wait(EC.presenceOf(fileElem), 2000,);
  • What is the outcome of trying to run your code? Do you get an error message? If so, what is it? Which line of code fails?
    – Kate Paulk
    Commented Sep 12, 2018 at 11:31
  • i have attached the error message with my question....kindly check it
    – Shakeel
    Commented Sep 13, 2018 at 7:42

2 Answers 2


You are getting this error, because you are trying to use 'sendKeys' method on an element whose type is not 'input'.

Use :

var fileElem=element(by.css('input[id="cropper-file-input"]'));

This worked for me:

it('should upload a file', function() {
  var fileToUpload = '../some/path/foo.txt',

  absolutePath =path.resolve(__dirname,fileToUpload);


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.