Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to close file upload dialogue after click on upload button in protractor

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?

like image 746
chirag panchani Avatar asked Nov 19 '22 16:11

chirag panchani


1 Answers

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!

like image 51
Dušan Panić Avatar answered Nov 21 '22 06:11

Dušan Panić