1

I am trying to upload a file by using sendKeys method and adding absolute path to file but the file does not get uploaded. I think sendKeys method doesn't work very well on react pages. Can someone please help and give a workaround of this problem? Below is the code snippet: I do not see any error but the file doesn't get uploaded.

Below is the function I am using to upload file:

importFileButton: {
  get: function() {
    return this.findElement(this.by.xpath("//div[@id='upload-file']//button[@aria-label='Import file Browse ']"))
  }
}


attachCommaFile: {
        get: function () {
            browser.setFileDetector(new remote.FileDetector());
            var fileToUpload = './../../files/fileimport_Pipe.txt',
                absolutePath = path.resolve(__dirname, fileToUpload);
            return this.importFileButton.sendKeys(absolutePath);
        }
    }
Sergey Pleshakov
  • 7,964
  • 2
  • 17
  • 40
Neha M
  • 33
  • 5

1 Answers1

1

file uploads work with input tags

You're trying to sendKeys to a wrong element - button

Most like the tag you're looking for will have the following css [type=file]

for more detailed info see this post https://stackoverflow.com/a/66110941/9150146

Sergey Pleshakov
  • 7,964
  • 2
  • 17
  • 40