I want to upload an image file in protractor. the problem is i can not get "input[type = "file"]"
element without clicking on upload button.
when I click upload button, file upload dialogue popup opens.
i have tried
browser.actions().sendKeys(protractor.Key.ESCAPE).perform();
but it does not work.
This is what I am doing:
var image = '../images/image1.png';
var absPathImg = path.resolve(__dirname, image);
element(by.id('uploadImage')).click();
browser.actions().sendKeys(protractor.Key.ESCAPE).perform();
element(by.css('input[type=file]')).sendKeys(absPathImg);
element(by.id('upload')).click();
How can i close that file upload dialogue to upload an image?
Try it like this. I used this for Protractor, but I think it's similar for Selenium. I also have a problem for Windows File dialog not closing. This is how I solved that:
element(by.css('elementForOpenDialog')).sendKeys(absPathImg);
Send Keys to the element which will open file dialog, not click on element to open file dialog. Just send to that element absolute path and it will upload without opening dialog. It's worked for me. Good Luck!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With