FileDetector

Used with WebElement#sendKeys on file input elements (<input type="file">) to detect when the entered key sequence defines the path to a file.

By default, WebElement's will enter all key sequences exactly as entered. You may set a file detector on the parent WebDriver instance to define custom behavior for handling file elements. Of particular note is the selenium-webdriver/remote.FileDetector, which should be used when running against a remote Selenium Server.

Constructor

new FileDetector()

Methods

(package) handleFile(_driver, path) → (non-null) {Promise.<string>}

Handles the file specified by the given path, preparing it for use with the current browser. If the path does not refer to a valid file, it will be returned unchanged, otherwise a path suitable for use with the current browser will be returned.

This default implementation is a no-op. Subtypes may override this function for custom tailored file handling.

Parameters:
NameTypeDescription
_driver
pathstring

The path to process.

Returns:

A promise for the processed file path.

Type: 
Promise.<string>

handleFile()

Prepares a file for use with the remote browser. If the provided path does not reference a normal file (i.e. it does not exist or is a directory), then the promise returned by this method will be resolved with the original file path. Otherwise, this method will upload the file to the remote server, which will return the file's path on the remote system so it may be referenced in subsequent commands.

FileDetector

A webdriver.FileDetector that may be used when running against a remote Selenium server.

When a file path on the local machine running this script is entered with WebElement#sendKeys, this file detector will transfer the specified file to the Selenium server's host; the sendKeys command will be updated to use the transferred file's path.

Note: This class depends on a non-standard command supported on the Java Selenium server. The file detector will fail if used with a server that only supports standard WebDriver commands (such as the ChromeDriver).

Constructor

new FileDetector()

Methods

(package) handleFile(_driver, path) → (non-null) {Promise.<string>}

Handles the file specified by the given path, preparing it for use with the current browser. If the path does not refer to a valid file, it will be returned unchanged, otherwise a path suitable for use with the current browser will be returned.

This default implementation is a no-op. Subtypes may override this function for custom tailored file handling.

Parameters:
NameTypeDescription
_driver
pathstring

The path to process.

Returns:

A promise for the processed file path.

Type: 
Promise.<string>

handleFile()

Prepares a file for use with the remote browser. If the provided path does not reference a normal file (i.e. it does not exist or is a directory), then the promise returned by this method will be resolved with the original file path. Otherwise, this method will upload the file to the remote server, which will return the file's path on the remote system so it may be referenced in subsequent commands.