4

I'm using selenium webdriver with node.js (javascript ) under chrome.

In some test , i have to upload a file using his relative path (my file to upload is in the same directory as the test file)

var fileInput = driver.findElement(webdriver.By.xpath('//*[@id="j_idt69:j_idt70_input"]'));
fileInput.sendKeys('./file.xml');

Strangely my test fails and i catch this error :

My error handler... WebDriverError: unknown error: path is not absolute: 

In fact am using a relative path because my test is intented to be used in differents locations (VMs , jenkins , pc..). and the absolute path isn't usefull for me.

Suggestions ??

3
  • how about finding out an absolute path dynamically and using it? Commented May 10, 2017 at 9:07
  • './file.xml' mewans your file is in project directory, is it so? Commented May 10, 2017 at 9:08
  • @kushal : yes it is Commented May 10, 2017 at 9:47

2 Answers 2

5

i have solved it this way :

detecting the absolute path dynamically and concat it with my file name :

To detect the current directory path using this node command : process.cwd()

the resulting path is : var path = process.cwd()+'/file.xml';

uploading action : fileInput.sendKeys(path);

Sign up to request clarification or add additional context in comments.

Comments

1

sendKeys not support relative path as a argument.

Use System.getProperty("user.dir") to get current working directory path.

 String path=System.getProperty("user.dir")
 fileInput.sendKeys(path+"\\file.xml");

Comments

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.