Uploade File In Protractor

[Solved] Uploade File In Protractor | Perl - Code Explorer | yomemimo.com
Question : uploade file in protractor

Answered by : vast-vendace-ghwfisompfxz

var path = require('path');
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();
});
Use the path module to resolve the full path of the file that you want to upload.
Set the path to the input type="file" element.
Click on the upload button.
This will not work on firefox. Protractor will complain because the element is not visible. To upload in firefox you need to make the input visible. This is what I do:
browser.executeAsyncScript(function(callback) { // You can use any other selector document.querySelectorAll('#input-file-element')[0] .style.display = 'inline'; callback();
});
// Now you can upload.
$('input[type="file"]').sendKeys(absolutePath);
$('#uploadButton').click();

Source : https://stackoverflow.com/questions/21305298/how-to-upload-file-in-angularjs-e2e-protractor-testing | Last Update : Thu, 14 Jul 22

Answers related to uploade file in protractor

Code Explorer Popular Question For Perl