0

The following command executes correctly when running on local:

String fileLocation = "/Users/local/file.xlsx";
chro.findElement(By.xpath("//input[@title='input']")).sendKeys(fileLocation);

But fails when running remotely (on selenium grid) with following exception: org.openqa.selenium.InvalidArgumentException: invalid argument: File not found : /Users/local/file.xlsx Does anyone know what might be the reason?

Yulaz
  • 81
  • 8

2 Answers2

0

According to the error you are getting, it seems that the path /Users/local/file.xlsx is not present on the server you are executing the script on.

To fix the issue, you can make a folder named exceldata inside your automation project and inside that folder you can insert your test data excel sheet file.xlsx and then you can set the path using System.getProperty("user.dir") (which gives the project directory path on the current system) and then you can set the xlsx path by using:

String fileLocation = System.getProperty("user.dir") + "/exceldata/file.xlsx";

Now, the above fileLocation is not dependent of the machine you are running the script on and can be used anywhere independently.

Sameer Arora
  • 4,439
  • 3
  • 10
  • 20
  • I should've been more descriptive... My project structure precisely follows your suggestion. I have a dedicated folder containing test files within workspace and use system property to derive it's location. What I was referring to above is a case where my local box was running a set against remote: local -> grid. – Yulaz Mar 08 '19 at 01:12
  • Just found the answer - https://stackoverflow.com/a/16244627/9336888 TLDR: use FileDetector to send your file over the wire. driver = new RemoteWebDriver(new URL(hubUrl), options); ((RemoteWebDriver) driver).setFileDetector(new LocalFileDetector()); – Yulaz Mar 08 '19 at 01:23
0

Found the answer - stackoverflow.com/a/16244627/9336888

TLDR: use FileDetector to send your file over the wire.

driver = new RemoteWebDriver(new URL(hubUrl), options); 
((RemoteWebDriver) driver).setFileDetector(new LocalFileDetector());
Yulaz
  • 81
  • 8