1

I was wondering what's the way to handle remote file upload with selenium-webdriver in typescript?

In javascript, this bit of code works:

import remote from 'selenium-webdriver/remote';
// import * as remote from 'selenium-webdriver/remote'; // used for typescript

browser.setFileDetector(new remote.FileDetector());
uploadElement.sendKeys(path.resolve(__dirname, f));

But in typescript, I'm getting Property 'FileDetector' does not exist on type 'typeof remote'. I have both @types/selenium-webdriver and selenium-webdriver installed already.

"@types/selenium-webdriver": "^2.53.39",
"selenium-webdriver": "^3.0.1"

Edit: Update with suggestion from bcherny

import { FileDetector } from 'selenium-webdriver';

return fileDetector.handleFile(browser.driver, f).then((fPath) => {
  browser.setFileDetector(fileDetector);

  return uploadElement.sendKeys(path.resolve(__dirname, fPath))
}

Edit: Working code

import * as remote from 'selenium-webdriver/remote';

browser.setFileDetector(new remote.FileDetector());
return uploadElement.sendKeys(path.resolve(__dirname, f))

2 Answers 2

1

You want

import { FileDetector } from 'selenium-webdriver'

See https://github.com/DefinitelyTyped/DefinitelyTyped/blob/76a710cc945a34dcf664ded78937c9b957b3eccd/selenium-webdriver/test/index.ts#L485

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

2 Comments

So I was a bit confused with that. In the typings for selenium-webdriver, it says to use selenium-webdriver/remote.FileDetector for remote upload
Did you try the code above, and does it work? The file I linked is the tests for the selenium-webdriver typings.
0

Working code, had to import from the remote typings

import * as remote from 'selenium-webdriver/remote';

browser.setFileDetector(new remote.FileDetector());
return uploadElement.sendKeys(path.resolve(__dirname, f))

1 Comment

Can you explain what you have did here?

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.