1

The HTML is as follows:
<input type="file" style="display: none" ng-file-select="" ng-file-change="upload($files)" ng-multiple="multiple" accept=".jpg,.png">

I need to upload file to the element which uses ng-file-upload for uploading image file using Protractor:

var uploadFile = element(by.css('input[type="file"]'));
uploadFile.sendKeys('C:\\Temp\\test.png');
uploadFile.evaluate("openMetadataDialog({file:imgFile})");

The above is however not working. I am not able to understand how to upload the file! As per my understanding, as soon as I sendkeys to input element, the upload function should be called itself! However, that does not seem to be happening!

Regards,
Sakshi

9
  • I am not sure about the 3rd line - why are you calling openMetadataDialog()? Is there a submit button on a form that contains the file input? Thanks. Commented Mar 17, 2015 at 5:42
  • Yes. There is a Submit button which sends the File and some metadata regarding the file(description etc) Commented Mar 17, 2015 at 6:16
  • 1
    I think you just need to click that submit button after sending keys to the file input. Commented Mar 17, 2015 at 6:18
  • That used to work when ng-file-upload was not used at the backend for file upload. Commented Mar 17, 2015 at 6:46
  • @alecxe: Any idea bout the above info? Is there a way in which I can pass a new File() parameter to openMetadataDialog function? Commented Mar 19, 2015 at 7:05

1 Answer 1

2

It seems that ng-file-upload doesn't react to .sendKeys(...), its file-change doesn't get invoked. You can use standard onchange event to invoke some custom upload logic:

<input type="file" 
       style="display: none"     
       onchange="angular.element(this).scope().upload(this)" 
       ng-file-select 
       ng-multiple="multiple" 
       accept=".jpg,.png">

this points to the input element which has a property files.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.