Patricio Lussenhoff
Patricio Lussenhoff

Reputation: 11

protractor does not recognize '\' at uploading a file

I've been reading a few answers to this and implemented one of those. Here is my code:

    var path = require('path');
    var fileToUpload = "C:\Users\patricio.lussenhoff\Desktop\test.txt",
    absolutePath = path.resolve(__dirname, fileToUpload);
    var type3 = browser.element(by.css('[type="file"]'));
    type3.sendKeys(absolutePath);

The protractor apparently is not recognizing the slashes (I've tried '/' way too) and the control shows like this:

here is the example I'm talking about

Any thoughts ?

Upvotes: 0

Views: 271

Answers (2)

Nick
Nick

Reputation: 504

Based on the OS Use single forward slash(Linux, Unix, etc.,) or double backward slash(Windows) to read files:

var fileToUpload = "C:/Users/patricio.lussenhoff/Desktop/test.txt",
var fileToUpload = "C:\\Users\\patricio.lussenhoff\\Desktop\\test.txt",

Upvotes: 0

flaviomeira10
flaviomeira10

Reputation: 586

Try it:

var fileToUpload = "C:\\Users\\patricio.lussenhoff\\Desktop\\test.txt";    
var type3 = browser.element(by.css('[type="file"]'));
type3.sendKeys(fileToUpload);

This way you don't need to use 'path.resolve' because you are passing the complete and correct path.

Upvotes: 0

Related Questions