0

I'm having an issue with Selenium standalone webdriver used with webdriver-manager npm module. I'm using the Firefox Gecko driver. I need to select a file from an HTML file input component. When I try this on my local machine or on BrowserStack I get the error:

"WebDriverError: File not found: /Users/christophergrigg/a.pdf"

const requestFile = By.id('requestFile');
driver.wait(until.elementLocated(requestFile));
const requestFileEl = driver.findElement(requestFile);
driver.wait(until.elementIsVisible(requestFileEl), TIMEOUT).click();
requestFileEl.sendKeys('/Users/christophergrigg/a.pdf');
requestFileEl.sendKeys(webdriver.Key.ENTER);

On Browser stack I'm using this path:

requestFileEl.sendKeys('C:\\Desktop\\documents\\pdf-sample2.pdf'); // Windows 7 / 8 / 8.1
Christopher Grigg
  • 2,238
  • 27
  • 33

1 Answers1

2

You need to provide the full path of the file. And if the file is not present on the machine running the remote instance, you'll also have to set the file detector to automatically upload the file.

On mac OS X:

var remote = require('selenium-webdriver/remote');
driver.setFileDetector(new remote.FileDetector);
driver.sendKeys('/Users/christophergrigg/Desktop/a.pdf');

, or Windows:

var remote = require('selenium-webdriver/remote');
driver.setFileDetector(new remote.FileDetector);
driver.sendKeys('C:\\Users\\christophergrigg\\Desktop\\a.pdf');
Florent B.
  • 41,537
  • 7
  • 86
  • 101
  • Thanks for your response the remote upload will be handy. The issue happens on my local machine even with the full path though, so I'm stuck at step 1. – Christopher Grigg Sep 14 '17 at 12:42
  • I'm actually seeing the same thing. I was just running some automation on IE and I was getting the same error. It worked fine on Chrome and FF but on IE it was reporting that the file was not found. I took the path from the error message and tried it and it found the file just fine... so I'm stumped as to what the issue might be as well. – JeffC Sep 14 '17 at 13:01