Each WebDriver instance provides automated control over a browser session.
| Name | Type | Attributes | Description |
|---|---|---|---|
session | |||
executor | command. | The executor to use when sending commands to the browser. | |
onQuit | function | <optional> | A function to call, if any, when the session is terminated. |
Creates a new action sequence using this driver. The sequence will not be submitted for execution until Actions.perform() is called.
| Name | Type | Attributes | Description |
|---|---|---|---|
options | Object | <optional> | Configuration options for the action sequence (see Actions documentation for details). |
A new action sequence for this instance.
Injects a credential into the authenticator.
| Name | Type | Description |
|---|---|---|
credential | Credential to be added |
Adds a virtual authenticator with the given options.
| Name | Type | Description |
|---|---|---|
options | VirtualAuthenticatorOptions object to set authenticator options. |
Closes the current window.
A promise that will be resolved when this command has completed.
Creates a new WebSocket connection.
A new CDP instance.
Executes the provided command.Command using this driver's command.Executor.
| Name | Type | Description |
|---|---|---|
command | command. | The command to schedule. |
A promise that will be resolved with the command result.
Executes a snippet of asynchronous JavaScript in the context of the currently selected frame or window. The script fragment will be executed as the body of an anonymous function. If the script is provided as a function object, that function will be converted to a string for injection into the target window.
Any arguments provided in addition to the script will be included as script arguments and may be referenced using thearguments object. Arguments may be a boolean, number, string, orWebElement. Arrays and objects may also be used as script arguments as long as each item adheres to the types previously mentioned.
Unlike executing synchronous JavaScript with #executeScript, scripts executed with this function must explicitly signal they are finished by invoking the provided callback. This callback will always be injected into the executed function as the last argument, and thus may be referenced witharguments[arguments.length - 1]. The following steps will be taken for resolving this functions return value against the first argument to the script's callback function:
Example #1: Performing a sleep that is synchronized with the currently selected window:
var start = new Date().getTime();driver.executeAsyncScript( 'window.setTimeout(arguments[arguments.length - 1], 500);'). then(function() { console.log( 'Elapsed time: ' + (new Date().getTime() - start) + ' ms'); });Example #2: Synchronizing a test with an AJAX application:
var button = driver.findElement(By.id('compose-button'));button.click();driver.executeAsyncScript( 'var callback = arguments[arguments.length - 1];' + 'mailClient.getComposeWindowWidget().onload(callback);');driver.switchTo().frame('composeWidget');driver.findElement(By.id('to')).sendKeys('dog@example.com');Example #3: Injecting a XMLHttpRequest and waiting for the result. In this example, the inject script is specified with a function literal. When using this format, the function is converted to a string for injection, so it should not reference any symbols not defined in the scope of the page under test.
driver.executeAsyncScript(function() { var callback = arguments[arguments.length - 1]; var xhr = new XMLHttpRequest(); xhr.open("GET", "/resource/data.json", true); xhr.onreadystatechange = function() { if (xhr.readyState == 4) { callback(xhr.responseText); } }; xhr.send('');}).then(function(str) { console.log(JSON.parse(str)['food']);});| Name | Type | Attributes | Description |
|---|---|---|---|
script | string | | The script to execute. | |
args | * | <repeatable> | The arguments to pass to the script. |
A promise that will resolve to the scripts return value.
Executes a snippet of JavaScript in the context of the currently selected frame or window. The script fragment will be executed as the body of an anonymous function. If the script is provided as a function object, that function will be converted to a string for injection into the target window.
Any arguments provided in addition to the script will be included as script arguments and may be referenced using thearguments object. Arguments may be a boolean, number, string, orWebElement. Arrays and objects may also be used as script arguments as long as each item adheres to the types previously mentioned.
The script may refer to any variables accessible from the current window. Furthermore, the script will execute in the window's context, thusdocument may be used to refer to the current document. Any local variables will not be available once the script has finished executing, though global variables will persist.
If the script has a return value (i.e. if the script contains a return statement), then the following steps will be taken for resolving this functions return value:
| Name | Type | Attributes | Description |
|---|---|---|---|
script | string | | The script to execute. | |
args | * | <repeatable> | The arguments to pass to the script. |
A promise that will resolve to the scripts return value.
Locates an element on the page. If the element cannot be found, a error.NoSuchElementError will be returned by the driver.
This function should not be used to test whether an element is present on the page. Rather, you should use #findElements:
driver.findElements(By.id('foo')) .then(found => console.log('Element found? %s', !!found.length));The search criteria for an element may be defined using one of the factories in the webdriver.By namespace, or as a short-hand webdriver.By.Hash object. For example, the following two statements are equivalent:
var e1 = driver.findElement(By.id('foo'));var e2 = driver.findElement({id:'foo'});You may also provide a custom locator function, which takes as input this instance and returns aWebElement, or a promise that will resolve to a WebElement. If the returned promise resolves to an array of WebElements, WebDriver will use the first element. For example, to find the first visible link on a page, you could write:
var link = driver.findElement(firstVisibleLink);function firstVisibleLink(driver) { var links = driver.findElements(By.tagName('a')); return promise.filter(links, function(link) { return link.isDisplayed(); });}| Name | Type | Description |
|---|---|---|
locator | by. | The locator to use. |
A WebElement that can be used to issue commands against the located element. If the element is not found, the element will be invalidated and all scheduled commands aborted.
Search for multiple elements on the page. Refer to the documentation on #findElement(by) for information on element locator strategies.
| Name | Type | Description |
|---|---|---|
locator | by. | The locator to use. |
A promise that will resolve to an array of WebElements.
Navigates to the given URL.
| Name | Type | Description |
|---|---|---|
url | string | The fully qualified URL to open. |
A promise that will be resolved when the document has finished loading.
Retrieves a list of all available window handles.
A promise that will be resolved with an array of window handles.
Initiates bidi connection using 'webSocketUrl'
A promise that will resolve with the instance's capabilities.
The list of credentials owned by the authenticator.
Retrieves the URL for the current page.
A promise that will be resolved with the current URL.
The command executor used by this instance.
Retrieves the current page's source. The returned source is a representation of the underlying DOM: do not expect it to be formatted or escaped in the same way as the raw response sent from the web server.
A promise that will be resolved with the current page source.
A promise for this client's session.
Retrieves the current page title.
A promise that will be resolved with the current page's title.
Retrieves the current window handle.
A promise that will be resolved with the current window handle.
Retrieves 'webSocketDebuggerUrl' by sending a http request using debugger address
| Name | Type | Description |
|---|---|---|
debuggerAddress | string | |
target | ||
caps |
Returns parsed webSocketDebuggerUrl obtained from the http request
| Name | Type | Description |
|---|---|---|
connection | ||
callback |
The options interface for this instance.
The navigation interface for this instance.
| Name | Type | Description |
|---|---|---|
webElementPromise | function | The webElement in unresolved state |
First single WebElement from array of resolved promises
Handle Network interception requests
| Name | Type | Description |
|---|---|---|
connection | WebSocket connection to the browser | |
httpResponse | Object representing what we are intercepting as well as what should be returned. | |
callback | callback called when we intercept requests. |
| Name | Type | Description |
|---|---|---|
connection | ||
callback |
| Name | Type | Description |
|---|---|---|
connection | ||
callback |
Takes a PDF of the current page. The driver makes a best effort to return a PDF based on the provided parameters.
| Name | Type | Description |
|---|---|---|
options | Object |
Terminates the browser session. After calling quit, this instance will be invalidated and may no longer be used to issue commands against the browser.
A promise that will be resolved when the command has completed.
Sets a listener for Fetch.authRequired event from CDP If event is triggered, it enters username and password and allows the test to move forward
| Name | Type | Description |
|---|---|---|
username | string | |
password | string | |
connection | CDP Connection |
Removes all the credentials from the authenticator.
Removes a credential from the authenticator.
| Name | Type | Description |
|---|---|---|
credential_id | The ID of the credential to be removed. |
Removes a previously added virtual authenticator. The authenticator is no longer valid after removal, so no methods may be called.
Sets the file detector that should be used with this instance.
| Name | Type | Description |
|---|---|---|
detector | input. | The detector to use or |
Sets whether the authenticator will simulate success or fail on user verification.
| Name | Type | Description |
|---|---|---|
verified | true if the authenticator will pass user verification, false otherwise. |
Makes the driver sleep for the given amount of time.
| Name | Type | Description |
|---|---|---|
ms | number | The amount of time, in milliseconds, to sleep. |
A promise that will be resolved when the sleep has finished.
The target locator interface for this instance.
Takes a screenshot of the current page. The driver makes the best effort to return a screenshot of the following, in order of preference:
A promise that will be resolved to the screenshot as a base-64 encoded PNG.
The value of authenticator ID added
Waits for a condition to evaluate to a "truthy" value. The condition may be specified by aCondition, as a custom function, or as any promise-like thenable.
For aCondition or function, the wait will repeatedly evaluate the condition until it returns a truthy value. If any errors occur while evaluating the condition, they will be allowed to propagate. In the event a condition returns a Promise, the polling loop will wait for it to be resolved and use the resolved value for whether the condition has been satisfied. The resolution time for a promise is always factored into whether a wait has timed out.
If the provided condition is aWebElementCondition, then the wait will return aWebElementPromise that will resolve to the element that satisfied the condition.
Example: waiting up to 10 seconds for an element to be present on the page.
async function example() { let button = await driver.wait(until.elementLocated(By.id('foo')), 10000); await button.click();}| Name | Type | Attributes | Description |
|---|---|---|---|
condition | IThenable.<T> | | The condition to wait on, defined as a promise, condition object, or a function to evaluate as a condition. | |
timeout | number | <optional> | The duration in milliseconds, how long to wait for the condition to be true. |
message | string | | <optional> | An optional message to use if the wait times out. |
pollTimeout | number | <optional> | The duration in milliseconds, how long to wait between polling the condition. |
if the providedcondition is not a valid type.
A promise that will be resolved with the first truthy value returned by the condition function, or rejected if the condition times out. If the input condition is an instance of aWebElementCondition, the returned value will be aWebElementPromise.
Creates a new WebDriver session.
This function will always return a WebDriver instance. If there is an error creating the session, such as the aforementioned SessionNotCreatedError, the driver will have a rejected session promise. This rejection will propagate through any subsequent commands scheduled on the returned WebDriver instance.
let required = Capabilities.firefox();let driver = WebDriver.createSession(executor, {required});// If the createSession operation failed, then this command will also// also fail, propagating the creation failure.driver.get('http://www.google.com').catch(e => console.log(e));| Name | Type | Attributes | Description |
|---|---|---|---|
executor | command. | The executor to create the new session with. | |
capabilities | Capabilities | The desired capabilities for the new session. | |
onQuit | function | <optional> | A callback to invoke when the newly created session is terminated. This should be used to clean up any resources associated with the session. |
The driver for the newly created session.