3

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:

image.

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);
 console.log(absolutePath);
 var fileElem=element(by.css('label[for="cropper-file-input"]'));
 browser.wait(EC.presenceOf(fileElem), 2000,);
 fileElem.sendKeys(absolutePath);
  • 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 Sep 12 '18 at 11:31
  • i have attached the error message with my question....kindly check it – Shakeel Sep 13 '18 at 7:42
0

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"]'));
0

This worked for me:

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

  absolutePath =path.resolve(__dirname,fileToUpload);

  element(by.css('input[type="file"]')).sendKeys(absolutePath);    
  element(by.id('uploadButton')).click();
});

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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