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

4
  • Hey i am also facing same issue , did you get any solution ? Commented Jul 25, 2018 at 12:13
  • As of now i have not got any solutions let me know if you found any. Commented Aug 9, 2018 at 10:01
  • hey i got solution , Just call below method which i customized and uploads file without opening that windows upload dialog Commented Aug 10, 2018 at 7: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); } Commented Aug 10, 2018 at 7:12

1 Answer 1

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');
Sign up to request clarification or add additional context in comments.

1 Comment

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());

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.