1

Trying to automate uploading .xml/pdf format files (Windows based popup) from local system to web application (Angualrjs) using Protractor framework.

Scenario: Browser the application in Chrome> Click upload button> web app popup comes where able to locate elements > click Browse button on upload field (This field would be disabled, only click event is allowed which opens windows popup to browse files)> Here we have challenge to browse the file.

After clicking Browse button performed> Window popup shows Documents location however we want to browse and upload the file from Desktop or from Project location.

Followed other stackoverflow references as given below but unable to solve: How to upload file in angularjs e2e protractor testing

Scripts which we tried:

iUploadConfigDefinition : (sPath) => {

  var absolutePath = path.resolve(__dirname, sPath);
    uploadInput.sendKeys(absolutePath);
}

Here not sure what should be 'uploadInput' element locator and how to recognize/fetch Open button of windows popup.

Please guide. Attached the screen for reference.

enter image description here

  • Hey i am also facing same issue , did you get any solution ? – simond Jul 25 '18 at 12:13
  • As of now i have not got any solutions let me know if you found any. – Protractor Learner Aug 09 '18 at 10:01
  • hey i got solution , Just call below method which i customized and uploads file without opening that windows upload dialog – simond Aug 10 '18 at 07:10
  • function selectFile(fileName: string) { var path = require('path'); var remote = require('../../node_modules/selenium-webdriver/remote'); browser.setFileDetector(new remote.FileDetector()); var fileToUpload = 'c:\Files'+fileName;//e.g fileName is 'file.png' var absolutePath = path.resolve(process.cwd() + fileToUpload); element(by.css('input[type="file"]')).sendKeys(absolutePath); } – simond Aug 10 '18 at 07:12

1 Answers1

1

Please try the following solution :

browser.findElement(by.xpath("path of the browse button"));
browser.findElement(by.css('input[type=file]')).sendKeys('full path of the file with extension');
Simon N
  • 337
  • 2
  • 13
Shrutika
  • 48
  • 6
  • It is key, as above, not to click the button. It looks like from your picture the input box is visible and can be typed in. If not between the two lines in this answer, you might need to interpolate the following: browser.executeScript("arguments[0].style.visibility = 'visible'; ", element(by.css("input[type=file]")).getWebElement()); – Jeremy Kahan Aug 10 '18 at 02:25